HowSearchmanagerAssociated with user dictionary?
First, let's take a look at the search
1) In your<Activity>
, An intent filter, and a reference toSearchable. xml
File (described below ):
<Intent-filter>
<Action Android: Name = "Android. Intent. Action. Search" />
<Category Android: Name = "Android. Intent. Category. Default" />
</Intintent-filter>
<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 bySearch suggestionsSection of the searchmanager docs:
<! -- Provides search suggestions for words and their definitions. -->
<Provider Android: Name = "Dictionaryprovider"
Android: Authorities = "Dictionary"
Android: syncable = "False" />
InSearchable. 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 ofSearchable. 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 thatAndroid: searchsuggestauthority
Attribute refers to the authority of the content provider we declared inAndroidmanifest. xml
.
To makeSearchCan containDictionary, We need to do:
- 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
- CreateContent ProviderTo perform all search and suggestion queries
- UseSimplecursoradapterTo 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 customBaseadapter
,
See the SDK samples encoded with the platforms for API Level 4-6.
In fact, the search framework does not provide APIs for searching data added by users. To achieve our goal,
You must use APIs that support our data. What should I do? For example, if the data has SQLite database,
You should use Android. database. SQLite APIs to complete searches.