在我的代码中,我显示了从gridview中的sdcard中获取的图像。现在我希望图像按升序排列的最后修改日期排序。我尝试使用Collections。排序和比较。但它显示错误。 她是我的代码 荫本根据日期对图像进行排序并在gridview中显示
ArrayList<String> f = new ArrayList<String>();
File[] listFile;
String ExternalStorageDirectoryPath = Environment
.getExternalStorageDirectory().getAbsolutePath();
String targetPath = ExternalStorageDirectoryPath + "/saved_images";
File targetDirector = new File(targetPath);
imageList = new ArrayList<String>();
File[] files = targetDirector.listFiles();
for (File i : files) {
imageList.add(i.getAbsolutePath());
}
检索从SD卡的图片,我试图collections.sort比较对列表进行排序基于日期
Collections.sort(imageList,new Comparator<Object>()
{
public int compare(Object o1, Object o2) {
if (((File)o1).lastModified() > ((File)o2).lastModified()) {
return -1;
} else if (((File)o1).lastModified() < ((File)o2).lastModified()) {
return +1;
} else {
return 0;
}
}
});
lazyloadadapter = new LazyLoadAdapter(getActivity(), imageList);
gV.setAdapter(lazyloadadapter);
但IAM获得的Java错误。 lang.ClasscastEception字符串不能转换为文件。
java.lang中。ClassCastException错误 – Viveka 2014-11-06 10:12:25
请准备您的查询以使用MediaStore.Images.Media.query()检查获取排序的列表图像:http://stackoverflow.com/questions/13824233/how-to-list-images-on-sd-card-按照时间排序 – 2014-11-06 10:14:53