2013-06-21 7 views
19

私は働く検索ウィジェットを持っており、検索履歴の提案を追加したいのですが。私はAndroidのチュートリアル(http://developer.android.com/guide/topics/search/adding-recent-query-suggestions.html)に従っていますが、検索は動作しますが、提案は表示されません。ここに私のコードです:Android SearchRecentSuggestions - SearchViewでの入力時に提案が表示されない

  1. コンテンツプロバイダ

    <provider 
        android:name=".SearchHistoryProvider" 
        android:authorities="com.mypackage.SearchHistoryProvider"> 
    </provider> 
    
  2. 検索可能な構成

    <?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> 
    
  3. マニフェストでプロバイダを宣言

    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); 
        } 
    } 
    
  4. 提案は、実際には表示されませんを除いて(私の検索可能な活動で)コンテンツプロバイダへのクエリを保存する

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

すべてが(検索が、私はそれらを追加する前と同じように見えます)、正常に動作します。どんな助けでも大歓迎です!

+0

ああ、私はこの問題を解決しました。 Androidのマニフェスト設定(プロバイダ名)の間違いでした。どのように賞金を取り除くことができますか? –

+0

@ Eng.Fouad他の人のために賞金を払うと賞金を取り除くことはできません。 –

+0

@ Eng.Fouadモデレータは極端な場合に賞金を払い戻すことができます。この投稿にフラグを立てて "その他"を選択し、あなたのケースを誓約することができます。まだ遅すぎることはありません。 :) –

答えて

2

Manifest.xmlのSearchHistoryProvider の宣言が間違っていたと思います。

android:name=".SearchHistoryProvider" 

ライティングの$ NAMEが $ DEFAULTPACKAGEの省略形です$ NAMEは、あなたの$ DEFAULTPACKAGEは 'com.myapp' の場合よう はウントあなたがアンドロイドとして.SearchHistoryProviderを記述します。あなたの プロバイダーの名前を、アンドロイド次のコードの最初の行に示すように、 com.mypackageにあるので、単にそれを見つけることはできません。

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); 
    } 
} 
関連する問題