Android search history quick search

I am setting up a quick search to display data from my application. His work is wonderful. Now the problem: when I click the search button, I can not see the search history. What should I do to get my search history (previously found keywords)?

Very urgent, can someone help me how to get this?

+3
source share
1 answer

If you read the tutorial on developer.android.com, I think you will find what you are looking for:

http://developer.android.com/guide/topics/search/adding-recent-query-suggestions.html

The trick is to implement a ContentProvider that extends SearchRecentSuggestionsProvider. This is a simple class:

public class MySuggestionProvider extends SearchRecentSuggestionsProvider {
  public final static String AUTHORITY = "com.example.MySuggestionProvider";
  public final static int MODE = DATABASE_MODE_QUERIES;

  public MySuggestionProvider() {
      setupSuggestions(AUTHORITY, MODE);
  }
}

searchable.xml, :

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
  android:label="@string/app_label"
  android:hint="@string/search_hint"
  android:searchSuggestAuthority="com.example.MySuggestionProvider"
  android:searchSuggestSelection=" ?" >
</searchable>

:

if (Intent.ACTION_SEARCH.equals(Intent .getAction())) {
  String query = Intent .getStringExtra(SearchManager.QUERY);
  SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
      MySuggestionProvider.AUTHORITY, MySuggestionProvider.MODE);
  suggestions.saveRecentQuery(query, null);
}
+2

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


All Articles