网络调用在Filter.performFiltering
方法内部执行:
@Override
public Filter getFilter() {
Filter filter = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
if (constraint != null) {
// Retrieve the autocomplete results.
resultList = autocomplete(constraint.toString());
// Assign the data to the FilterResults
filterResults.values = resultList;
filterResults.count = resultList.size();
}
return filterResults;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
if (results != null && results.count > 0) {
notifyDataSetChanged();
}
else {
notifyDataSetInvalidated();
}
}};
return filter;
}
从文档中可以看出,该Filter.performFiltering()
方法在工作线程中执行:
在工作线程中调用以根据约束过滤数据。子类必须实现此方法才能执行过滤操作。过滤操作计算的结果必须以 a 返回Filter.FilterResults
,然后将通过 发布在 UI 线程中publishResults(CharSequence,
android.widget.Filter.FilterResults)
。