我创建了Recyclerview,我想在此回收视图上应用搜索过滤器。我已经执行了下面的代码。但是在performFiltering()期间,它在logcat中显示错误,如下所示。
我的代码:
public CustomFilter(List<SearchAgentbean.GetSearchAgent> filterList, SearchAgentAdapter adapter)
{
this.adapter=adapter;
this.filterList=filterList;
}
//FILTERING OCURS
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results=new FilterResults();
//CHECK CONSTRAINT VALIDITY
if(constraint != null && constraint.length() > 0)
{
//CHANGE TO UPPER
constraint=constraint.toString().toUpperCase();
//STORE OUR FILTERED PLAYERS
ArrayList<SearchAgentbean.GetSearchAgent> filteredPlayers=new ArrayList<>();
for (int i=0;i<filterList.size();i++)
{
//CHECK
Logger.i("SEARCH","SEARCH"+filterList.get(i).getUSERNAME());
if(filterList.get(i).getUSERNAME().toUpperCase().contains(constraint))
{
//ADD PLAYER TO FILTERED PLAYERS
filteredPlayers.add(filterList.get(i));
}
}
results.count=filteredPlayers.size();
results.values=filteredPlayers;
}else
{
results.count=filterList.size();
results.values=filterList;
}
return results;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
adapter.marrayagentdata= (List<SearchAgentbean.GetSearchAgent>) results.values;
//REFRESH
adapter.notifyDataSetChanged();
}