【发布时间】:2016-12-03 09:22:39
【问题描述】:
我有一个 searchView 和一个 Listview。我有以下方法来过滤我的 Listview
@Override
public boolean onQueryTextChange(String query) {
if (TextUtils.isEmpty(query)) {
listAdapter = new CustomExpandableListAdapter(getApplicationContext(), readList (getBaseContext(),"Categories"), FinalMap);
expandableListView.setAdapter(listAdapter);
} else {
listAdapter = new CustomExpandableListAdapter(getApplicationContext(), readList (getBaseContext(),"Categories"), FinalMap);
listAdapter.filterData(query);
expandableListView.setAdapter(listAdapter);
}
return true;
}
当我转到下一个活动并按返回时,我的问题就开始了,我的 FinalMap 变为 null,因此适配器无法正常工作。
当我评论 QueryTextChange 代码时,onBackPressed 方法工作正常!
同时我删除了 searchView 焦点,但它似乎没有导致问题。
更新:
@Override
public boolean onQueryTextChange(String query) {
if (TextUtils.isEmpty(query))
{
return false;
} else {
listAdapter = new CustomExpandableListAdapter(getApplicationContext(), readList (getBaseContext(),"Categories"), FinalMap);
listAdapter.filterData(query);
expandableListView.setAdapter(listAdapter);
return true;
}
}
现在通过此更改,我可以返回,但如果我键入并搜索并从列表中找到某些内容,则它无法正常工作,打开它并尝试返回
如何处理这样的问题?
感谢您的宝贵时间
【问题讨论】:
-
你能把你的活动的完整代码吗?