gpt4 book ai didi

android - Android 快速搜索中的搜索历史记录

转载 作者:太空狗 更新时间:2023-10-29 13:42:20 25 4
gpt4 key购买 nike

我正在自定义快速搜索以显示来 self 的应用程序的数据。它工作正常。现在的问题是,当我点击搜索按钮时,我看不到搜索历史。获取历史搜索记录(之前搜索过的关键词)怎么办?

最佳答案

如果您浏览了 developer.android.com 上的教程,我想您会找到您要找的东西:

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

技巧是实现一个扩展 SearchRecentSuggestionsProvider 的 ContentProvider。这是一个简单的类:

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

请记住将您的提供商添加到 list 中,并更新您的 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>

此外,您还需要将搜索保存在您的可搜索 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 - Android 快速搜索中的搜索历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4212520/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com