我有一個搜索小部件(SearchView),在輸入時顯示自定義建議。我已按照official guide添加最近的查詢建議,但我仍然只有自定義建議。
對於每個搜索,我的片段調用這個函數(驗證):最近的搜索沒有顯示,自定義建議是
private void addQueryToRecent(String query) {
SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getActivity(),
MyCustomSuggestionProvider.AUTHORITY,
MyCustomSuggestionProvider.MODE);
suggestions.saveRecentQuery(query, "recent");
}
我的建議提供者似乎確定:
public class MyCustomSuggestionProvider extends SearchRecentSuggestionsProvider {
public final static String AUTHORITY = "com.zgui.musicshaker.provider.MyCustomSuggestionProvider";
public final static int MODE = DATABASE_MODE_QUERIES | DATABASE_MODE_2LINES;
public MyCustomSuggestionProvider() {
setupSuggestions(AUTHORITY, MODE);
}
@Override
public Cursor query(Uri uri, String[] projection, String sel,
String[] selArgs, String sortOrder) {
//retrieves a custom suggestion cursor and returns it
}
}
searchable.xml:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="artist, track informations..."
android:label="@string/app_name"
android:queryAfterZeroResults="true"
android:searchSuggestAuthority="com.zgui.musicshaker.provider.MyCustomSuggestionProvider"
android:searchSuggestSelection=" ?" />
清單:
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<provider
android:name=".provider.MyCustomSuggestionProvider"
android:authorities="com.zgui.musicshaker.provider.MyCustomSuggestionProvider"
android:enabled="true" >
</provider>
Acording到that post,我應該是有數據/數據/ app.package.name /數據庫/ databasename.db最近的搜索分貝,但我似乎沒有...
或者,也許我是否應該在MyCustomSuggestionProvider.query()返回的遊標中自己添加「最近的搜索建議」?任何想法是值得歡迎...
你沒有使用SearchSuggestionProvider,怎麼回事? –