sorting - How to sort SDCard image based on date in android -


i trying sort sdcard image gridview baseed on date. tried variety of codes. cant able achieve this. please provide me help.

public class sdcard extends activity {  //  cursor used access results querying images on sd card.  private cursor cursor;   // column index thumbnails image ids.  private int columnindex;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_sdcard);      // set array of thumbnail image id column want     string[] projection = {mediastore.images.thumbnails._id};     // create cursor pointing sdcard     cursor = managedquery( mediastore.images.thumbnails.external_content_uri,             projection, // columns return             null,       // return rows             null,             mediastore.images.thumbnails.image_id);     // column index of thumbnails image id     columnindex = cursor.getcolumnindexorthrow(mediastore.images.thumbnails._id);      gridview sdcardimages = (gridview) findviewbyid(r.id.gridview1);     sdcardimages.setadapter(new imageadapter(this));   } 

// image adapter link images gridview

private class imageadapter extends baseadapter {      private context context;      public imageadapter(context localcontext) {         context = localcontext;     }      public int getcount() {         return cursor.getcount();     }     public object getitem(int position) {         return position;     }     public long getitemid(int position) {         return position;     }     public view getview(int position, view convertview, viewgroup parent) {         imageview picturesview;         if (convertview == null) {             picturesview = new imageview(context);             // move cursor current position             cursor.movetoposition(position);             // current value requested column             int imageid = cursor.getint(columnindex);             // set content of image based on provided uri             picturesview.setimageuri(uri.withappendedpath(                     mediastore.images.thumbnails.external_content_uri, "" + imageid));             picturesview.setscaletype(imageview.scaletype.fit_xy);             picturesview.setpadding(10, 10, 10, 10);             picturesview.setlayoutparams(new gridview.layoutparams(100, 100));         }         else {             picturesview = (imageview)convertview;         }         return picturesview;     } } 

}

thius code working fine in emulator , not working in mobile.

a simple solution sort files path base on lastmodified date

    file sd = new file(**pathofimagesfiles**);     file[] sdfilelist = sd.listfiles();     if (sdfilelist != null && sdfilelist.length > 1) {         arrays.sort(sdfilelist, new comparator<file>() {              @override              public int compare(file object1, file object2) {                 return object1.lastmodified() - object2.lastmodified();              }         });     } 

this may !


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -