diff --git a/docs/html/guide/topics/search/adding-custom-suggestions.jd b/docs/html/guide/topics/search/adding-custom-suggestions.jd index 9ea4c8be48ea2..ce0c619536889 100644 --- a/docs/html/guide/topics/search/adding-custom-suggestions.jd +++ b/docs/html/guide/topics/search/adding-custom-suggestions.jd @@ -5,74 +5,88 @@ parent.link=index.html
-

Key classes

-
    -
  1. {@link android.app.SearchManager}
  2. -
  3. {@link android.content.SearchRecentSuggestionsProvider}
  4. -
  5. {@link android.content.ContentProvider}
  6. -

In this document

  1. The Basics
  2. -
  3. Modifying the searchable configuration
  4. +
  5. Modifying the Searchable Configuration
  6. Creating a Content Provider
    1. Handling a suggestion query
    2. Building a suggestion table
  7. -
  8. Declaring an Intent for suggestions +
  9. Declaring an Intent for Suggestions
    1. Declaring the Intent action
    2. Declaring the Intent data
  10. Handling the Intent
  11. -
  12. Rewriting the query text
  13. -
  14. Exposing search suggestions to Quick Search Box
  15. +
  16. Rewriting the Query Text
  17. +
  18. Exposing Search Suggestions to Quick Search Box
+ +

Key classes

+
    +
  1. {@link android.app.SearchManager}
  2. +
  3. {@link android.content.SearchRecentSuggestionsProvider}
  4. +
  5. {@link android.content.ContentProvider}
  6. +
+ +

Related Samples

+
    +
  1. Searchable +Dictionary
  2. +
+

See also

  1. Searchable Configuration
  2. Content Providers
  3. -
  4. Searchable -Dictionary sample app
-

The Android search framework provides the ability for your application to -provide suggestions while the user types into the Android search dialog. In this guide, you'll learn -how to create custom suggestions. These are suggestions based on custom data provided by your -application. For example, if your application is a word dictionary, you can suggest words from the -dictionary that match the text entered so far. These are the most valuable suggestions because you -can effectively predict what the user wants and provide instant access to it. Once you provide -custom suggestions, you then make them available to the system-wide Quick Search Box, providing -access to your content from outside your application.

+

When using the Android search dialog, you can provide custom search suggestions that are +created from data in your application. For example, if your application is a word +dictionary, you can suggest words from the +dictionary that match the text entered so far. These are the most valuable suggestions, because you +can effectively predict what the user wants and provide instant access to it. Figure 1 shows +an example of a search dialog with custom suggestions.

-

Before you begin, you need to have implemented the Android search dialog for searches in your -application. If you haven't done this, see Using the Android Search +

Once you provide custom suggestions, you can also make them available to the system-wide Quick +Search Box, providing access to your content from outside your application.

+ +

Before you begin with this guide to add custom suggestions, you need to have implemented the +Android search dialog for searches in your +application. If you haven't, see Using the Android Search Dialog.

The Basics

- +
+ +

Figure 1. Screenshot of a search dialog with custom +search suggestions.

+
-

When the user selects a custom suggestions, the Search Manager will send a customized Intent to -your searchable Activity. Whereas a normal search query will send an Intent with the {@link +

When the user selects a custom suggestion, the Search Manager sends an {@link +android.content.Intent} to +your searchable Activity. Whereas a normal search query sends an Intent with the {@link android.content.Intent#ACTION_SEARCH} action, you can instead define your custom suggestions to use -{@link android.content.Intent#ACTION_VIEW} (or any other action), and also include additional data +{@link android.content.Intent#ACTION_VIEW} (or any other Intent action), and also include data that's relevant to the selected suggestion. Continuing the dictionary example, when the user selects a suggestion, your application can immediately open the definition for that word, instead of searching the dictionary for matches.

-

To provide custom suggestions, you need to do the following:

+

To provide custom suggestions, do the following:

-

Just like the Search Manager handles the rendering of the search dialog, it will also do the work -to display all search suggestions below the search dialog. All you need to do is provide a source -from which the suggestions can be retrieved.

- -

Note: If you're not familiar with creating Content -Providers, please read the Content +

Just like the Search Manager displays the search dialog, it also displays your search +suggestions. All you need is a content provider from which the Search Manager can retrieve your +suggestions. If you're not familiar with creating content +providers, read the Content Providers developer guide before you continue.

-

When the Search Manager identifies that your Activity is searchable and also provides search -suggestions, the following procedure will take place as soon as the user types into the Android -search box:

+

When the Search Manager identifies that your Activity is searchable and provides search +suggestions, the following procedure takes place as soon as the user enters text into the +search dialog:

- +
  • Search Manager displays the list of suggestions provided by the Cursor.
  • + -

    At this point, the following may happen:

    +

    Once the custom suggestions are displayed, the following might happen: