Android搜索小部件 - 后退箭头按钮功能

时间:2016-07-13 01:41:49

标签: android search back-button back searchbar

我正在尝试向搜索窗口小部件后退按钮添加功能。现在,它只关闭搜索栏。我还希望它关闭搜索列表并在搜索之前返回原始列表。

Search Widget Back Button Image

附件是我的搜索代码。

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.options_menu, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));


    return true;
}

@Override
protected void onNewIntent(Intent intent) {
    handleIntent(intent);
}

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        winelist = dbHelper.searchWineList(query);
        adapter.clear();
        adapter.addAll(winelist);
        adapter.notifyDataSetChanged();
    }
}

1 个答案:

答案 0 :(得分:0)

SearchView的监听器会监听搜索的结束,您是否尝试过回调以重置整个列表?