`

Android如何把SearchManager和User Dictionary联系在一起

 
阅读更多

如何把SearchManager和User Dictionary联系在一起?

先了解一下Search

1) In your <activity>, an intent filter, and a reference to a searchable.xml file (described below):

<intent-filter>
 <action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />

2) A content provider that can provide search suggestions according to the URIs and column formats specified by the Search Suggestions section of the SearchManager docs:

<!-- Provides search suggestions for words and their definitions. -->
<provider android:name="DictionaryProvider"
android:authorities="dictionary"
android:syncable="false" />

In the searchable.xml file, you specify a few things about how you want the search system to present search for your app, including the authority of the content provider that provides suggestions for the user as they type. Here's an example of the searchable.xml of an Android app that provides search suggestions within its own activities:


<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/search_label"
android:searchSuggestAuthority="dictionary"
android:searchSuggestIntentAction="android.intent.action.VIEW">
</searchable>

Note that the android:searchSuggestAuthority attribute refers to the authority of the content provider we declared in AndroidManifest.xml.

为了让search的范围可以包含dictionary,我们需要做:

  • Implement a search interface using Android's search framework
  • Provide custom search suggestions and offer them in Quick Search Box
  • Create an SQLite database and an FTS3 table for full-text searches
  • Create a content provider to perform all search and suggestion queries
  • Use SimpleCursorAdapter to bind data from a Cursor to a ListView.

Note: For the original version of Searchable Dictionary,

which reads words from a file instead of a database and uses a custom BaseAdapter,

see the SDK samples included with the platforms for API Level 4-6.

事实上,search framework 并没有提供搜索用户添加的数据的API,为了达到我们的目的,

必须使用支持我们的数据相关的API。怎么说呢?比如说,数据存在SQLite database,那么,

就应该使用android.database.sqlite APIs 来完成 searches 。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics