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 。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值