如何把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 。
整合SearchManager与UserDictionary
本文介绍如何在Android应用中将SearchManager与UserDictionary结合使用,实现自定义搜索建议及全文搜索功能。文章涵盖创建搜索接口、提供快速搜索框建议、建立SQLite数据库及全文搜索表等步骤。
916

被折叠的 条评论
为什么被折叠?



