2013-06-21 1 views
19

작동하는 검색 위젯이 있고 검색 기록 제안을 추가하고 싶습니다. 안드로이드 튜토리얼 (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" 

쓰기 $ 이름이 $ 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); 
    } 
} 
관련 문제