Hemanth S
Hemanth S

Reputation: 688

How to implement the search function in android

how to implement search box like Google apps do in action-bar or else is there any libs for that suggestions, in my app i have custom list view with numbers according to them, i just want to search those numbers that's it any help thanks

Upvotes: 0

Views: 3545

Answers (1)

Ussef Ben Amor
Ussef Ben Amor

Reputation: 96

Add Item menu Search !

  <item
    android:id="@+id/option_menu_search"
    app:actionViewClass="android.support.v7.widget.SearchView"
    android:icon="@drawable/ic_search_white_24dp"
    android:orderInCategory="10"
    app:showAsAction="ifRoom|collapseActionView"
    android:title="@string/abc_searchview_description_search"
    >

add in your onOptionsItemSelected

SearchView searchView = (SearchView) menu.findItem(R.id.option_menu_search).getActionView();

then

 searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(String query) {

                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {

                return true;
            } });

Upvotes: 2

Related Questions