私は働く検索ウィジェットを持っており、検索履歴の提案を追加したいのですが。私はAndroidのチュートリアル(http://developer.android.com/guide/topics/search/adding-recent-query-suggestions.html)に従っていますが、検索は動作しますが、提案は表示されません。ここに私のコードです:Android SearchRecentSuggestions - SearchViewでの入力時に提案が表示されない
コンテンツプロバイダ
<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>
マニフェストでプロバイダを宣言
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); } }
提案は、実際には表示されませんを除いて(私の検索可能な活動で)コンテンツプロバイダへのクエリを保存する
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モデレータは極端な場合に賞金を払い戻すことができます。この投稿にフラグを立てて "その他"を選択し、あなたのケースを誓約することができます。まだ遅すぎることはありません。 :) –