Limiting the number of search suggestions, android

岁酱吖の 提交于 2019-12-11 03:39:59

问题


Is there a way to limit the number of displayed suggestions, when using the search interface with custom search suggestion?

Thanks!


回答1:


It's very simple actually.

Firstly in your ContentProvider, define a variable to have a reference to:

public static final String LIMIT_PARAMETER = "LIMIT";

In your Cursor query @Override of the provider define something to hold your limit value

String limit = uri.getQueryParameter(LIMIT_PARAMETER);

Then pass the limit to the SqliteQueryBuilder:

final Cursor cursor = queryBuilder.query(db, projection, selection,
        selectionArgs, null, null, sortOrder, limit);

You can then use it with a contentResolver like so:

getContentResolver().query( 
    SOME_CONTENT_URI.buildUpon().appendQueryParameter(
        YourContentProvider.LIMIT_PARAMETER, yourLimit).build(), 
    mSuggestionProjection, mSelection,
    filterArgArray, ORDER_BY );


来源:https://stackoverflow.com/questions/23217595/limiting-the-number-of-search-suggestions-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!