EasySearchView
nicolkill
10
Visit GitHub RepoSearch Inputs

Easy SearchView

Download Build Status

Easy SearchView is a library that to implement search in any view only setting the data.

Features

  • Easy implementation
  • Good look

For more functions or bugs, create a issue.

Usage

Step 1:

Add gradle dependecy

dependencies {
  compile 'com.nicolkill:easysearchview:{latest_release}'
}

Step 2:

Add the following xml on your view:

<com.nicolkill.easysearchview.EasySearchView
    android:id="@+id/search_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

Step 3:

Add SearchElement interface on your class, in this example i use SuperRecyclerView for the list:

@LayoutResource(R.layout.row)
public class Option implements SearchElement {

    private static final String TAG = Option.class.getSimpleName();

    private int mOptionNumber;

    public Option(int number) {
        mOptionNumber = number;
    }

    @BindField(id = R.id.option_name)
    public String getOptionName() {
        return "Option " + (mOptionNumber + 1);
    }

    @Override
    public String toString() {
        return getOptionName();
    }

//  The following methods is of the interface

//  This define if the option can be showed on the search
    @Override
    public boolean isSearchPosibillity(String search) {
        return getOptionName().toLowerCase().contains(search.toLowerCase());
    }

//  get the principal object to use later
    @Override
    public Object getObject() {
        return this;
    }

//  the view resource on layouts
    @Override
    public int getViewRes() {
        return R.layout.row_search;
    }

//  this set the values on view
    @Override
    public void render(View view) {
        TextView textView = (TextView) view.findViewById(R.id.text);
        textView.setText(getOptionName());
    }
}

Step 4:

Get reference and set data:

EasySearchView searchView = (EasySearchView) findViewById(R.id.search_container);
searchView.setData(data);

Step 5:

Customize the adapter with the functions and listeners that you want

// click
adapter.setOnClickListener(new ClickListener<Option>() {
    @Override
    public void onItemSelected(View view, int position, Option element) {
        Snackbar.make(view, "Click option selected: " + element.getOptionName(), Snackbar.LENGTH_SHORT).show();
    }
});
Become a better Android Developer
Millions of developers are learning at MindOrks

Online Training Program

Featured Blogs

Our Team

MindOrks is Certainly one of the best online blog to stay on top of all the Android development news, coding and design patterns. Finally a blog I can count on to keep myself updated with latest and greatest things happening in Android world.

Vipul Shah
Android Developer
Microsoft

Become Pro in Android by watching videos

OUR LEARNERS WORK AT