Я показываю некоторые данные в ListView, используя свой собственный класс ArrayAdapter. У меня есть счетчик в Action Bar и на основе его выбора элементов. Я хочу фильтровать данные и переписывать их в виде списка.Пользовательский ListView ArrayAdapter не отображает отфильтрованные данные
В настоящее время, когда моя активность загружается, данные отображаются правильно, но когда я выбираю любой элемент из счетчика, ListView пуст и не отображает никаких данных, хотя панель действий по-прежнему появляется.
Не могли бы вы рассказать мне, что я делаю неправильно?
Это мой обычай ArrayAdapter Класс:
public class MyAdapter extends ArrayAdapter implements Filterable {
private ArrayList < ArrayList <String>> arrayList;
private LayoutInflater theInflater;
public MyAdapter(Context context, ArrayList arrayList) {
super(context, R.layout.row_layout, arrayList);
this.arrayList = arrayList;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
theInflater = LayoutInflater.from(getContext());
View theView = theInflater.inflate(R.layout.row_layout, parent, false);
ArrayList <String> values = (ArrayList <String>) getItem(position);
TextView a= (TextView) theView.findViewById(R.id.a);
TextView b= (TextView) theView.findViewById(R.id.b);
TextView c= (TextView) theView.findViewById(R.id.c);
a.setText(values.get(0));
b.setText(values.get(1));
c.setText(values.get(2));
return theView;
}
public Filter geFilter() {
Filter filter = new Filter() {@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
ArrayList al = new ArrayList();
al.add("ValueA1");
al.add("ValueA2");
al.add("ValueA3");
ArrayList bl = new ArrayList();
bl.add("ValueB1");
bl.add("ValueB2");
bl.add("ValueB3");
ArrayList < ArrayList <String>> array = new ArrayList < >();
array.add(al);
array.add(bl);
results.count = array.size();
results.values = array;
return results;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
arrayList = (ArrayList) results.values;
notifyDataSetChanged();
}
};
return filter;
}
}
В пункте выбран слушателем Прядильщиков, у меня есть:
theAdapter.getFilter().filter("Incoming");
Вы должны пройти прямую выделенную позицию, результат фильтра будет пустым для входящих – Rahul