Sort Files In Sdcard By Date Created
I need to sort files from sdcard folder by date created in android,i have saved files in sdcard folder using system date,can anyone help me in solving this?
Solution 1:
use a Collection.sort:
Collections.sort(list, new Comparator<File>() {
publicintcompare(File o1, File o2) {
long lastModifiedO1 = o1.lastModified();
long lastModifiedO2 = o2.lastModified();
return (lastModifiedO1 < lastModifiedO2) ? -1 : ((lastModifiedO1 > lastModifiedO2) ? 1 : 0);
}
});
Check for typo
Solution 2:
Collection sort is the way to go as the others are suggesting.
Used this code awhile ago :
Collections.sort(mFileList, new Comparator<File>() {
publicintcompare(File f1, File f2) {
return Long.valueOf(f2.lastModified()).compareTo(
f1.lastModified());
}
});
Solution 3:
You can get the Date of file one by one :
File f= newFile(filePath);
Date fileDate= newDate(f.lastModified());
And than Apply the Sorting Algorithm.
You'll achieve what you need
Post a Comment for "Sort Files In Sdcard By Date Created"