Reputation: 54949
I have an Activity which has a Action Bar on the top with a Search View. Also i am using Custom List View and want to filter from the key words entered in the search view should be associated with a particular text view in the List View Item.
Upvotes: 4
Views: 6273
Reputation: 6240
in your onQueryTextChange(String Text) method of Listener use: adapter.getFilter().filter(Text.toString()); and implement your filter in your BaseAdapter class. here is the sample code:
@Override
public Filter getFilter()
{
return filter;
}
private GameFilter filter;
private class GameFilter extends Filter
{
public GameFilter() { }
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults oReturn = new FilterResults();
ArrayList<ItemDetails> results = new ArrayList<ItemDetails>();
if (orig == null)
orig = itemDetailsrrayList;
if (constraint != null)
{
if (orig != null && orig.size() > 0) {
for (ItemDetails g : orig) {
if (g.getName().toLowerCase().contains(constraint.toString().toLowerCase()))
results.add(g);
}
}
oReturn.values = results;
}
return oReturn;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results)
{
itemDetailsrrayList = (ArrayList<ItemDetails>)results.values;
notifyDataSetChanged();
}
}
Upvotes: 2