【问题标题】:How to show the search results in SearchView如何在 SearchView 中显示搜索结果
【发布时间】:2016-12-11 21:55:26
【问题描述】:

我使用工具栏搜索视图。我使用代码捕获输入结果:

SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        public boolean onQueryTextChange(String newText) {

            return true;
        }

当我得到结果时,我正在我的 excel 文件中寻找类似的字符串。然后我返回 ArrayList(搜索结果)。现在我需要在 SearchView 中显示结果。我该怎么做?

【问题讨论】:

    标签: android searchview


    【解决方案1】:

    您需要使用与您的搜索视图关联的 CursorAdapter。

    Searchview.setSuggestionAdapter
    

    有关使用数组中的光标的有用链接 (Create a cursor from hardcoded array instead of DB)。

    【讨论】:

    • 感谢您的回答。当我创建 SimpleCursorAdapter 时,我需要“to”数组,但我需要在 SearchView 中显示搜索结果。我不明白如何填写正确的 SimpleCursorAdapter?
    • 在您创建 SimpleCursorAdapter 并将其与 onCreateOptionsMenu 中的 SearchView 关联后,您需要使用 SearchView.setQueryTextListener 监听更改。在此回调 (onQueryTextChange) 中,您可以从数据创建一个新游标,并使用 CursorAdapter.swapCursor 将新游标传递给游标适配器。
    猜你喜欢
    • 1970-01-01
    • 2019-11-05
    • 2020-07-08
    • 1970-01-01
    • 2013-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多