Gowtham GS Gowtham GS - 6 months ago 33
Android Question

sorting images into gridview using date

I'm using the following code ,it picks image from gallery and displays image in random order

String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID };
String orderBy = MediaStore.Images.Media._ID;
imagecursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,null, orderBy);
int image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media._ID);


I want the images to get sorted via date it has been taken(Eg:Latest ones first and oldest photos later)...

and one more problem that when i use above code it only loads images in DCIM folder ,i want all the images from phone also.......

flx flx
Answer

Change orderBy to

String orderBy = MediaStore.Images.Media.DATE_TAKEN + " DESC";