我有一个带有搜索视图的操作栏的Activity,同时我正在使用自定义列表视图,并且想要从在搜索视图中输入的关键字过滤与列表视图项中特定文本视图相关联的内容。
@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();
}
}