我使用以下代码过滤我的,过滤完成后ArrayAdapter
我调用setAdapter
。由于某种原因,未过滤的数据在应用过滤器之前会在屏幕上闪烁。有任何想法吗?
mList = getData();
Collections.sort(mList);
mAdapter = new CustomItem(getActivity(), R.layout.list_item, mList);
String filter = mSpinner1.getSelectedItem().toString();
mAdapter.getFilter().filter(filter);
mListView.setAdapter(mAdapter);
这是我的自定义过滤器中的代码:
@Override
public Filter getFilter()
{
return new Filter()
{
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results)
{
mSubItems = (ArrayList<CustomItem>)results.values;
if (results.count > 0)
{
notifyDataSetChanged();
}
else
{
notifyDataSetInvalidated();
}
}
@Override
protected FilterResults performFiltering(CharSequence constraint)
{
setFilter(constraint);
List<CustomItem> filteredResults = getFilteredResults();
FilterResults results = new FilterResults();
results.values = filteredResults;
results.count = filteredResults.size();
return results;
}
};
}