【问题标题】:Why when I use TextUtils to control input on searchView onBackPressed method returns null in android?为什么当我使用 TextUtils 控制 searchView 上的输入时,onBackPressed 方法在 android 中返回 null?
【发布时间】: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;
}

}

现在通过此更改,我可以返回,但如果我键入并搜索并从列表中找到某些内容,则它无法正常工作,打开它并尝试返回

如何处理这样的问题?

感谢您的宝贵时间

【问题讨论】:

  • 你能把你的活动的完整代码吗?

标签: android listview


【解决方案1】:

我不知道这是否是正确的方法,但我在我的适配器和我的 filtermethod 中添加了以下重建我的 JSONObject 和我的详细信息列表

db = new SQLiteHandler(context);
    SavedResponse mysavedresponse = new SavedResponse();
    JSONObject j = null;
    JSONArray result = null;
    //Get my initial response saved in sqlite
    mysavedresponse = db.getMySavedResponse();
    String MyResponse = mysavedresponse.getSavedresponse();

    try {
        j = new JSONObject(MyResponse);
        //Storing the Array of JSON String to our JSON Array
        result = j.getJSONArray(AppConfig.JSON_ARRAY_LIST);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    expListDetail = AdapterGetUserOffers(result);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-03
    • 2023-03-17
    • 1970-01-01
    • 2011-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多