SearchManager - adding custom offers

I read all the online documentation about creating search interfaces and adding custom suggestions ... but I still don't understand how this works. The documentation says that I should "create a table (for example, in SQLiteDatabase) for your sentences and format the table with the necessary columns." I assume that the system will eventually fill this table with the appropriate sentences on its own ... but which process / class is responsible for this, and when the actual inserts will be performed (before the user makes a request, after the request was made by the user, etc. .)?

And although I ask a question here, if someone can clarify the difference between AutoCompleteTextView and SearchView w / custom sentences ... that would be awesome. AutoCompleteTextView seems suspiciously easy to implement compared to SearchView (which requires changes to the helper class ContentProvider , SQLiteDatabase, etc.).

+6
source share
1 answer

You need to create a content provider that delivers your custom offers based on the query you have entered so far in the search view. In your searchable.xml file, you configure the minimum length of the search expression that must be reached before requesting offers. This content provider is called an offer provider (it still extends ContentProvider). The content owner is also configured in the searchable.xml file.

There are no restrictions on how the offer provider calculates its offers. You can search the web query in the database or read the file. But the response to the request is in table format. If offers are directly requested from the database, you can use the cursor that the database query responds to deliver the result in the query () method of the content provider. If the result is calculated from one or more sources, you can create the table on the fly using MatrixCursor.

Response lines from the offer provider are used by the search engine to display offers, they are stored in a table. The format of the lines is as follows:

 private static final String[] COLUMNS = { "_id", SearchManager.SUGGEST_COLUMN_ICON_1, // ID of a drawable (icon) as String SearchManager.SUGGEST_COLUMN_TEXT_1, // main text for suggestion display SearchManager.SUGGEST_COLUMN_TEXT_2, // secondary text for suggestion display SearchManager.SUGGEST_COLUMN_INTENT_DATA, // this could be an URI to access the suggestion as used in an intent with a VIEW action SearchManager.SUGGEST_COLUMN_INTENT_ACTION, // this could be Intent.ACTION_VIEW SearchManager.SUGGEST_COLUMN_SHORTCUT_ID // eg SearchManager.SUGGEST_NEVER_MAKE_SHORTCUT }; 

The search is described here in more detail: http://developer.android.com/guide/topics/search/index.html

+5
source

Source: https://habr.com/ru/post/907140/


All Articles