Sfortunatamente, ContentResolver non può eseguire query con argomento limite. All'interno di ContentProvider, MySQLQueryBuilder può richiedere l'aggiunta del parametro limite aggiuntivo.
In seguito all'ordine del giorno, è possibile aggiungere una regola URI aggiuntiva all'interno di ContentProvider.
static final int ELEMENTS_LIMIT = 5;
public static final UriMatcher uriMatcher;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
........
uriMatcher.addURI(AUTHORITY, "elements/limit/#", ELEMENTS_LIMIT);
}
Poi, nel tuo metodo di interrogazione
String limit = null; //default....
switch(uriMatcher.match(uri)){
.......
case ELEMENTS_LIMIT:
limit = uri.getPathSegments().get(2);
break;
......
}
return mySQLBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder, limit);
Interrogazione ContentProvider dall'attività.
uri = Uri.parse("content://" + ContentProvider.AUTHORITY + "/elements/limit/" + 1);
//In My case I want to sort and get the greatest value in an X column. So having the column sorted and limiting to 1 works.
Cursor query = resolver.query(uri,
new String[]{YOUR_COLUMNS},
null,
null,
(X_COLUMN + " desc"));
fonte
2015-07-23 02:17:50
Solo un'idea. Ma puoi provare a mettere la clausola limite come ultimo parametro. Mi piace così activity.managedQuery (playlistUri, null, null, null, "limite 3")? – Renard