我有一个 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',或类似的)。其余建议将是来 self 的 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});
最佳答案
使用 MergeCursor 可能是可行的,我自己没有尝试过,但看起来它是为这种情况设计的。
当然,您必须使用静态数据构建自己的游标。
关于Android:是否可以在自定义搜索建议中插入永久选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5732901/