android在setOnSearchClickListener中显示搜索历史记录

时间:2015-11-26 13:04:07

标签: android

我想在用户点击searchView时显示所有搜索记录。(在setOnSearchClickListener上),但我的代码无法在setOnSearchClickListener中显示历史记录(它只显示我的吐司)。它在onQueryTextChange中运行良好。但我想在setOnSearchClickListener中。请帮帮我。

searchView.setOnSearchClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(mActivity,"hello",Toast.LENGTH_LONG).show();
                if (database != null) {
                    Cursor cursor = database.getAllSuggestions();
                    Log.d("cursor= ",cursor+"");
                    if (cursor.getCount() != 0) {
                        String[] columns = new String[]{SuggestionsDatabase.FIELD_SUGGESTION};
                        int[] columnTextId = new int[]{android.R.id.text1};

                        SuggestionSimpleCursorAdapter simple = new SuggestionSimpleCursorAdapter(mActivity.getBaseContext(),
                                R.layout.simple_list_item, cursor,
                                columns, columnTextId
                                , 0);

                        searchView.setSuggestionsAdapter(simple);
                    } else {

                    }
                }
            }
        });

0 个答案:

没有答案