아쉽게도 ContentResolver는 제한 인수가 있는지 질의 할 수 없습니다. ContentProvider 내에서 MySQLQueryBuilder는 추가 한도 매개 변수를 추가하여 쿼리 할 수 있습니다.
아젠다 다음에 ContentProvider 내에 추가 URI 규칙을 추가 할 수 있습니다. 쿼리 방법 활동에서
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);
쿼리 컨텐트 프로에서 그런
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);
}
.
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"));
아이디어 만 있습니다. 그러나 마지막 절로 limit 절을 넣으려고 할 수 있습니다. 마찬가지로 activity.managedQuery (playlistUri, null, null, null, "limit 3")? – Renard