Android快速搜索中的搜索历史 [英] Search history in Android quick search

查看:60
本文介绍了Android快速搜索中的搜索历史的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在自定义快速搜索以显示我的应用程序中的数据.它的工作正常.现在的问题是,当我单击搜索按钮时,我看不到搜索历史.我应该如何获取搜索历史记录(以前搜索过的关键字)?

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)?

推荐答案

如果您遍历developer.android.com上的教程,我想您会找到所需的内容:

If you go through 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

诀窍是实现扩展SearchRecentSuggestionsProvider的ContentProvider.这是一个简单的类:

The trick is to implement a ContentProvider which extends SearchRecentSuggestionsProvider. 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);
  }
}

请记住将您的提供程序添加到清单中,并更新您的searchable.xml文件,以使其了解您的提供程序:

Remember to add your provider to the manifest, and update your searchable.xml file so that it knows of your provider:

<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);
}

这篇关于Android快速搜索中的搜索历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆