我坚持这个。 我在离子2中使用了角火2,我需要得到一个物体的长度:
private ArrayList<Food> filterFood = new ArrayList<Food>();
private ItemFilter mFilter = new ItemFilter();
public Filter getFilter() {
return mFilter;
}
private class ItemFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
if (constraint == null || constraint.length() == 0) {
results.values = food;
results.count = food.size();
}
else {
ArrayList<Food> filterFood = new ArrayList<Food>();
for (Food txtPlace : food) {
if (txtPlace.getName().toUpperCase().startsWith(constraint.toString().toUpperCase()))
filterFood.add(txtPlace);
}
results.values = filterFood;
results.count = filterFood.size();
}
return results;
}
@Override
protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
if (filterResults.count == 0)
notifyDataSetInvalidated();
else {
food = (ArrayList<Food>) filterResults.values;
notifyDataSetChanged();
}
}
}
如果对象存在,如何知道它是否存在?
感谢。