SearchManager - 添加自定义的建议 [英] SearchManager - adding custom suggestions

查看:203
本文介绍了SearchManager - 添加自定义的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有关构建的搜索界面和添加自定义的建议阅读所有的文档在线...但我还是不清楚这是如何工作。该文件说,我一定要建立一个表(如在SQLiteDatabase),您的建议和格式化表格所需的列。我假定系统将最终填满该表格在其自身相应的建议...但该方法/类负责此,当将实际的插入发生时(之前的任何查询是由用户作出,后一查询已取得由用户等)?

I've read all of the documentation online about building search interfaces and adding custom suggestions... but I'm still unclear on how this works. The documentation says that I must "Build a table (such as in an SQLiteDatabase) for your suggestions and format the table with required columns". I'm assuming the system will eventually fill this table with the appropriate suggestions on its own... but which process/class is responsible for this, and when will the actual insertions occur (before any query is made by the user, after a query has been made by the user, etc.)?

虽然我要问一个问题在这里,如果有人能够澄清之间的差异 AutoCompleteTextView 搜索查看 W /自定义的建议...那简直是真棒。 AutoCompleteTextView 似乎可疑容易实现较搜索查看(这需要作出的的ContentProvider ,SQLiteDatabase辅助类,等等)。

And while I'm asking a question up here, if someone could clarify the difference between an AutoCompleteTextView and a SearchView w/ custom suggestions... that'd be awesome. AutoCompleteTextView seems suspiciously easy to implement compared to the SearchView (which requires changes to be made to the ContentProvider, SQLiteDatabase helper class, etc.).

推荐答案

您必须创建它提供基于查询您的自定义建议在搜索视图到目前为止输入的内容提供商。在您的searchable.xml配置的搜索EX pression,必须寻求建议前达到的最小长度。此内容提供程序被调用的建议提供者(它仍然继承ContentProvider的)。内容提供商的权威也被配置在searchable.xml

You have to create a content provider which delivers your custom suggestions based on a query so far entered in the search view. In your searchable.xml you configure the minimum length of the search expression, which must be reached before asking for suggestions. This content provider is called a suggestion provider (it still extends ContentProvider). The content provider's authority is also configured in searchable.xml.

对于如何建议提供计算它的建议没有限制。你可以在网上搜索查询数据库或读取文件。但答案到查询是在一个表的格式。如果建议从数据库直接查询可以使用光标由数据库查询回答以在内容提供者的查询()方法递送的结果。如果结果是从一个或多个源计算可以通过使用一个MatrixCursor动态创建一个表

There is no limitation on how the suggestion provider computes its suggestions. You can search the web query a database or read a file. But the answer to the query is in the format of a table. If the suggestions is directly queried from a database you can use the cursor answered by the database query to deliver the result in the content provider's query() method. If the result is computed from one or more sources you can create a table on the fly by using a MatrixCursor.

这建议提供者的回答的行所用的搜索机制来显示建议,它们被存储在表中。行的格式如下:

The rows of the answer from the suggestion provider are used by the search mechanism to display the suggestion, they are stored in a table. The format of the rows is as follows:

private static final String[] COLUMNS = {
    "_id",
    SearchManager.SUGGEST_COLUMN_ICON_1,        // ID of a drawable (icon) as String
    SearchManager.SUGGEST_COLUMN_TEXT_1,        // main text for suggestion display
    SearchManager.SUGGEST_COLUMN_TEXT_2,        // secondary text for suggestion display
    SearchManager.SUGGEST_COLUMN_INTENT_DATA,   // this could be an URI to access the suggestion as used in an intent with a VIEW action
    SearchManager.SUGGEST_COLUMN_INTENT_ACTION, // this could be Intent.ACTION_VIEW
    SearchManager.SUGGEST_COLUMN_SHORTCUT_ID    // e.g. SearchManager.SUGGEST_NEVER_MAKE_SHORTCUT
};

搜索在这里更详细地描述:<一href="http://developer.android.com/guide/topics/search/index.html">http://developer.android.com/guide/topics/search/index.html

这篇关于SearchManager - 添加自定义的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆