Android如何把SearchManager和User Dictionary联系在一起
2011-02-22 23:55
295 查看
如何把SearchManager和UserDictionary联系在一起?
先了解一下Search
1)Inyour
[/code]
Note:FortheoriginalversionofSearchableDictionary,
whichreadswordsfromafileinsteadofadatabaseandusesacustom
seetheSDKsamplesincludedwiththeplatformsforAPILevel4-6.
事实上,searchframework并没有提供搜索用户添加的数据的API,为了达到我们的目的,
必须使用支持我们的数据相关的API。怎么说呢?比如说,数据存在SQLitedatabase,那么,
就应该使用android.database.sqliteAPIs来完成searches。
先了解一下Search
1)Inyour
<activity>,anintentfilter,andareferencetoa
searchable.xmlfile(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.xmlfile,youspecifyafewthingsabouthowyouwantthesearchsystemtopresentsearchforyourapp,includingtheauthorityofthecontentproviderthatprovidessuggestionsfortheuserastheytype.Here'sanexampleofthe
searchable.xmlofanAndroidappthatprovidessearchsuggestionswithinitsownactivities:
[/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:searchSuggestAuthorityattributereferstotheauthorityofthecontentproviderwedeclaredin
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。
相关文章推荐
- android 如何查询电话当中的联系人,并查询出联系次数
- Android之如何使用快速联系徽章
- 如何在Android Quick Search Box中添加自己的app,按照我的意愿去Search。
- android 中如何禁掉组件或package——PackageManager使用
- android 如何将电话簿SDN数字和其他普通的数字混合在一起?
- 如何将android源码生成eclipse可用的jar,以marvell的fmmanager为例
- Android应用开发—FragmentManager如何管理fragments
- android sdk manager 如何设置代理
- 如何让android sdk manager飞奔安装sdk
- 如何让android sdk manager飞奔安装sdk
- Eclipse中如何快速提高Android SDK Manager下载速度的方法
- dma_mmap_coherent 如何和iommu联系在一起呢?
- android studio for android learning (二十二 )如何在camera2中加载其它控件和当前摄像头视图显示在一起以及UI优化
- android中如何禁掉组件或package——PackageManager使用
- 如何将软件测试和数据库联系在一起(转)
- Android 基础总结:(十一)ContentResolver与ContentProvider如何关联在一起的
- android 如何实现apk search出现在系统的推荐列表里
- android contentResolver与contentProvider如何关联在一起的
- 如何在Android Quick Search Box中添加自己的app,按照我的意愿去Search。
- Android ServiceManager 如何注册和查找service