我有一個可用的搜索小部件,並希望添加搜索歷史記錄建議。我遵循Android教程(http://developer.android.com/guide/topics/search/adding-recent-query-suggestions.html),雖然搜索仍然有效,但沒有任何建議正在顯示。這裏是我的代碼:Android SearchRecentSuggestions - 在輸入時不會顯示建議SearchView
內容提供商
package com.mypackage; import android.content.SearchRecentSuggestionsProvider; public class SearchHistoryProvider extends SearchRecentSuggestionsProvider { public final static String AUTHORITY = SearchHistoryProvider.class.getName(); public final static int MODE = DATABASE_MODE_QUERIES; public SearchHistoryProvider() { setupSuggestions(AUTHORITY, MODE); } }
在清單
<provider android:name=".SearchHistoryProvider" android:authorities="com.mypackage.SearchHistoryProvider"> </provider>
檢索配置
<?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_name" android:hint="@string/search_hint" android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" android:searchSuggestAuthority="com.mypackage.SearchHistoryProvider" android:searchSuggestSelection=" ?"> </searchable>
聲明提供商保存查詢到內容提供商(在我搜索的Activity)
private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchHistoryProvider.AUTHORITY, SearchHistoryProvider.MODE); suggestions.saveRecentQuery(query, null); // Collapse the search view as a search is performed MenuItem searchItem = mMenu.findItem(R.id.search); SearchView searchView = (SearchView) mMenu.findItem(R.id.search).getActionView(); searchItem.collapseActionView(); searchView.setQuery("", false); // send the query to the global search activity for loading the data Intent globalSearchIntent = new Intent(this, GlobalSearchFragmentActivity.class); GroceryOTGUtils.copyIntentData(intent, globalSearchIntent); globalSearchIntent.putExtra(GlobalSearchFragmentActivity.GLOBAL_SEARCH, true); startActivity(globalSearchIntent); } }
一切工作正常,但建議不實際顯示(搜索看上去和以前一樣我加入他們)。任何幫助將不勝感激!
嗯,我解決了這個問題。這是Android清單配置(提供者的名稱)中的一個錯誤。我如何刪除賞金? –
@ Eng.Fouad如果你爲他人提供賞金,你不能刪除賞金! –
@ Eng.Fouad版主可以在極端情況下退還賞金,您可以嘗試標記此帖子,選擇「其他」並保證您的情況。還不算太晚。 :) –