我正在扩展阵列适配器,但我仍然得到旧的结果,你能告诉我有什么问题吗?
public class Adaptor extends ArrayAdapter<String> implements Filterable{
private ArrayList<String> items;
public Adaptor(Context context, int textViewResourceId, String[] objects) {
super(context, textViewResourceId, objects);
items = new ArrayList<String>();
for (int i = 0; i < objects.length ; i++)
items.add(objects[i]);
}
@Override
public int getCount() {
return items.size();
}
@Override
public String getItem(int position) {
return items.get(position);
}
@Override
public Filter getFilter() {
Filter myFilter = new Filter(){
@Override
protected FilterResults performFiltering(CharSequence arg0) {
FilterResults rezultate = new FilterResults();
ArrayList<String> chestii = new ArrayList<String>();
for (int i = 0; i < items.size() ; i++)
{
String tmp = items.get(i).toUpperCase();
if (tmp.startsWith(arg0.toString().toUpperCase()))
chestii.add(items.get(i));
}
rezultate.count = chestii.size();
rezultate.values = chestii;
return rezultate;
}
@Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
if (results != null && results.count > 0)
{
notifyDataSetChanged();
}
else notifyDataSetInvalidated();
}
};
return myFilter;
}
}