您的位置:首页 > 移动开发 > Android开发

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

2011-02-22 23:55 295 查看
如何把SearchManager和UserDictionary联系在一起?

先了解一下Search



1)Inyour
<activity>
,anintentfilter,andareferencetoa
searchable.xml
file(describedbelow):

<intent-filter>

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

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

2)AcontentproviderthatcanprovidesearchsuggestionsaccordingtotheURIsandcolumnformatsspecifiedbytheSearchSuggestionssectionoftheSearchManagerdocs:

<!--Providessearchsuggestionsforwordsandtheirdefinitions.-->
<providerandroid:name="DictionaryProvider"
android:authorities="dictionary"
android:syncable="false"/>

Inthe[code]searchable.xml
file,youspecifyafewthingsabouthowyouwantthesearchsystemtopresentsearchforyourapp,includingtheauthorityofthecontentproviderthatprovidessuggestionsfortheuserastheytype.Here'sanexampleofthe
searchable.xml
ofanAndroidappthatprovidessearchsuggestionswithinitsownactivities:
[/code]
<searchablexmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/search_label"
android:searchSuggestAuthority="dictionary"
android:searchSuggestIntentAction="android.intent.action.VIEW">
</searchable>


Notethatthe[code]android:searchSuggestAuthority
attributereferstotheauthorityofthecontentproviderwedeclaredin
AndroidManifest.xml
.[/code]



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


ImplementasearchinterfaceusingAndroid'ssearchframework
ProvidecustomsearchsuggestionsandoffertheminQuickSearchBox
CreateanSQLitedatabaseandanFTS3tableforfull-textsearches
Createacontentprovidertoperformallsearchandsuggestionqueries
UseSimpleCursorAdaptertobinddatafromaCursortoaListView.


Note:FortheoriginalversionofSearchableDictionary,
whichreadswordsfromafileinsteadofadatabaseandusesacustom
BaseAdapter
,
seetheSDKsamplesincludedwiththeplatformsforAPILevel4-6.

事实上,searchframework并没有提供搜索用户添加的数据的API,为了达到我们的目的,
必须使用支持我们的数据相关的API。怎么说呢?比如说,数据存在SQLitedatabase,那么,
就应该使用android.database.sqliteAPIs来完成searches。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: