我有DialogFragment。有两种情况。
请找到过滤代码
Override
public Filter getFilter() {
return filter;
}
Filter filter = new Filter() {
public String convertResultToString(Object resultValue) {
String str = ((ItemDto)(resultValue)).name;
return str;
}
@Override
protected FilterResults performFiltering(CharSequence constraint) {
if(constraint != null) {
mSuggestions.clear();
for (ItemDto item : mItemsAll) {
try {
if(item.name.toLowerCase().startsWith(constraint.toString().toLowerCase())){
mSuggestions.add(item);
}
} catch (Exception ex){}
}
FilterResults filterResults = new FilterResults();
filterResults.values = mSuggestions;
filterResults.count = mSuggestions.size();
return filterResults;
} else {
return new FilterResults();
}
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
@SuppressWarnings("unchecked")
ArrayList<ItemDto> filteredList = (ArrayList<ItemDto>) results.values;
if(results != null && results.count > 0) {
clear();
for (Itemdto c : filteredList) {
add(c);
}
notifyDataSetChanged();
}
}
};