lundi 20 avril 2015

How to make sort gallery thumbnails image by date

i developing one android applicaiton. This application get all thumbnail images in gallery. i want to sort by date but i can't do this action.

Please help me.

Get all images

// Set up an array of the Thumbnail Image ID column we want
String[] columns = {MediaStore.Images.Media._ID};

String orderBy = MediaStore.Images.Thumbnails._ID + " DESC LIMIT 10";

// Create the cursor pointing to the SDCard

cursor = getActivity().managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
        columns, // Which columns to return
        null,       // Return all rows
        null,
        orderBy);

// Get the column index of the Thumbnails Image ID
columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);

myGalleryImages = (GridView) view.findViewById(R.id.my_gallery);
myGalleryImages.setAdapter(new ImageAdapter(getActivity()));

set images

    // Move cursor to current position
    cursor.moveToPosition(position);
    // Get the current value for the requested column
    int imageID = cursor.getInt(columnIndex);
    // Set the content of the image based on the provided URI
    holder.image.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageID));

Aucun commentaire:

Enregistrer un commentaire