public int getItemCount() { if (cachedCount == -1) { Cursor cursor = resolver.query( getBaseUri(), new String[] {"count(*)"}, MediaStore.Images.ImageColumns.BUCKET_ID + " = ?", new String[] {String.valueOf(album.getId())}, null); try { cursor.moveToNext(); cachedCount = cursor.getInt(0); } finally { cursor.close(); } } return cachedCount; }
public ArrayList<ImageItem> getMediaItem(int start, int count) { ArrayList<ImageItem> images = new ArrayList<ImageItem>(); Uri uri = getBaseUri().buildUpon().appendQueryParameter("limit", start + "," + count).build(); Cursor cursor = resolver.query( uri, ImageItem.PROJECTION, MediaStore.Images.ImageColumns.BUCKET_ID + " = ?", new String[] {String.valueOf(album.getId())}, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC, " + MediaStore.Images.ImageColumns._ID + " DESC"); try { while (cursor.moveToNext()) { ImageItem image = new ImageItem(cursor); images.add(image); } } finally { cursor.close(); } return images; }