【问题标题】:Android: Is it possible to insert a permanent option into custom search suggestions?Android:是否可以在自定义搜索建议中插入永久选项?
【发布时间】:2011-04-20 15:32:44
【问题描述】:

我有一个具有搜索功能的 Android 应用程序,它使用 ContentProvider 来查询支持我的应用程序的 SQLite 数据库。当用户输入查询时,应用程序会提供自定义搜索建议,如 Android 文档 here 所述。

In addition to this I would like the search dialog to display a permanent option at the top of the custom search suggestions that when selected would perform a web search in the browser using the query (e.g., 'Search the web for xyz',或类似)。其余的建议将是来自我的 ContentProvider 的标准搜索建议。

是否有可能做到这一点,如果可以,怎么做?

编辑:

David 建议的解决方案有效。我做了这样的事情:

MatrixCursor cursor = new MatrixCursor(new String[] {BaseColumns._ID, 
      SearchManager.SUGGEST_COLUMN_TEXT_1});
cursor.addRow(new Object[] {0, "I'm always the top suggestion!"});
return new MergeCursor(new Cursor[] {cursor, mySearchSuggestionCursor});

【问题讨论】:

    标签: android search


    【解决方案1】:

    MergeCursor 可能是可能的,我自己没有尝试过,但看起来它是为这种情况设计的。

    当然,您必须使用静态数据构建自己的光标。

    【讨论】:

    • 感谢您的提示,大卫。我不知道 MergeCursor,我会试一试。
    • 谢谢,大卫。您的建议简单、正确,为我节省了很多时间!
    猜你喜欢
    • 1970-01-01
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多