Android SearchRecentSuggestions - suggestions do not get displayed when typing in SearchView

后端 未结 1 867
粉色の甜心
粉色の甜心 2021-02-18 16:30

I have a working search widget and want to add search history suggestions. I followed the Android tutorial (http://developer.android.com/guide/topics/search/adding-recent-query-

1条回答
  •  时光说笑
    2021-02-18 17:16

    I think the problem was, that the declaration of the SearchHistoryProvider in the Manifest.xml was wrong.

    android:name=".SearchHistoryProvider"
    

    Writing .$NAME is a shorthand for $DEFAULTPACKAGE.$NAME, so if your $DEFAULTPACKAGE is 'com.myapp' und you write .SearchHistoryProvider as the android:name of your Provider, Android will simply not find it, as it is located in com.mypackage, as the first line of the following code indicates.

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

    0 讨论(0)
提交回复
热议问题