對子值進行排序。 當我鍵入搜索工作正常,但當我刪除鍵入的信件列表不更新。Android擴展列表搜索視圖
我的模型類
public class Category {
public class SubCategory
{
public String name;
public SubCategory(String name)
{
this.name = name;
}
}
public String name;
public ArrayList<SubCategory> categories;
public Category(String name, ArrayList<SubCategory> categories)
{
this.name = name;
this.categories = categories;
}
}
適配器
private ArrayList<Category> data;
private ArrayList<Category> originalData;
public CategoryListAdapter(Context context, ArrayList<Category> data)
{
this.context = context;
this.data = data;
this.originalData = new ArrayList<>();
this.originalData.addAll(data); }
public Filter getFilter() {
MyFilter filter = new MyFilter();
return filter;
}
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
String filterString = constraint.toString().toLowerCase();
Log.i("Tag" , filterString);
final ArrayList<Category> processData = originalData;
if(filterString.isEmpty()){
results.values = processData;
results.count = processData.size();
Log.i("Tag" , "original"+ originalData.get(0).categories.size());
}else {
int count = processData.size();
ArrayList<Category> nlist = new ArrayList<>();
for (int i = 0; i < count; i++) {
Category cat = processData.get(i);
final ArrayList<RequestCategory> req_catgories = processData.get(i).categories;
final ArrayList<RequestCategory> new_list = new ArrayList<>();
for (RequestCategory req_catgory : req_catgories) {
if (req_catgory.display_name.toLowerCase().contains(filterString)) {
new_list.add(req_catgory);
Log.i("Sub category", "added");
}
}
cat.categories = new_list;
nlist.add(cat);
}
results.values = nlist;
results.count = nlist.size();
}
Log.i("VALUES", results.values.toString());
return results;
}
在那裏有問題的片段?我認爲我的原始列表在某處被修改了? 請幫忙嗎?
當您將文本傳遞給適配器進行過濾時,您是否在那裏應用了任何條件?可能是它沒有通過文本,如果它是空的 –
看到這個鏈接http://www.androidbegin.com/tutorial/android-search-listview-using-filter/,你的原始列表越來越修改,因爲你正在創建參考 – Meenal