Reputation: 57
I have already set up the search widget on the action bar as per viperbone's answer on How to add a SearchWidget to the ActionBar?, however I don't know what to put in the Search class to process the query.
All the items I want to search are in a simple ArrayList of Strings. I can handle the comparator, I just don't know how to pass the ArrayList and the query to the class to process it.
Please don't send me links, especially to the Android Developer site, because it is VERY confusing to me. I would really appreciate it if you could write some code for me to use specific to my situation.
Thanks in advance
Upvotes: 0
Views: 58
Reputation: 6728
If you are using SearchView with ListView then try following code:
listView.setAdapter(arrayAdapter);
listView.setTextFilterEnabled(true);
searchView.setIconifiedByDefault(false);
searchView.setOnQueryTextListener(this);
searchView.setSubmitButtonEnabled(true);
searchView.setQueryHint("Search...");
@Override
public boolean onQueryTextChange(String newText) {
if (TextUtils.isEmpty(newText)) {
listView.clearTextFilter();
} else {
listView.setFilterText(newText.toString());
}
return true;
}
Upvotes: 1