0

我希望我可以更改android searchview的查询限制和排序顺序,然后我在我的ExampleSearchRecentSuggestionsProvider中更改了查询方法,但没有任何反应。

public class ExampleSearchSuggestionProvider extends SearchRecentSuggestionsProvider {
public final static String AUTHORITY = "com.example.ExampleSearchSuggestionProvider";

public final static int MODE = DATABASE_MODE_QUERIES;

public ExampleSearchSuggestionProvider() {
    setupSuggestions(AUTHORITY, MODE);
}

public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
        String sortOrder) {
    uri = uri.buildUpon().appendQueryParameter("limit", "3").build();
    sortOrder = " DESC";
    return super.query(uri, projection, selection, selectionArgs, sortOrder);
}

}

<?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/menu_search_hint"
    android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
    android:searchSuggestAuthority="com.example.ExampleSearchRecentSuggestionsProvider"
    android:searchSuggestSelection=" ?" >
</searchable>

我在uri(uri = uri.buildUpon().appendQueryParameter("limit", "3").build(); )中添加了"limit=3",但是游标结果并没有被限制为3,游标返回了所有结果。我将顺序设置为“DESC”,但结果没有排序。

谢谢你。

4

0 回答 0