[英]Search history in Android quick search
I am customizing quick search to display data from my app. 我正在自定义快速搜索以显示我的应用程序中的数据。 Its working fine. 它的工作正常。 Now the issue is, When I click on search button, I am not able to see the search history. 现在的问题是,当我点击搜索按钮时,我无法看到搜索历史记录。 What should I do get the search history (previously searched keywords)? 我该怎么做才能获得搜索记录(以前搜索过的关键字)?
If you go through the tutorial on developer.android.com, I think you will find what you are looking for: 如果您浏览developer.android.com上的教程,我想您会找到您要找的内容:
http://developer.android.com/guide/topics/search/adding-recent-query-suggestions.html http://developer.android.com/guide/topics/search/adding-recent-query-suggestions.html
The trick is to implement a ContentProvider which extends SearchRecentSuggestionsProvider. 诀窍是实现一个扩展SearchRecentSuggestionsProvider的ContentProvider。 It's 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);
}
}
Remember to add your provider to the manifest, and update your searchable.xml file so that it knows of your provider: 请记住将您的提供程序添加到清单中,并更新您的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>
Also you will need to save the searches in your searchable activity: 您还需要将搜索保存在可搜索的活动中:
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.