我使用网格视图创建了一个示例库应用程序,现在我想 喜欢添加一个吐司,其中包含使用moto g,
等图像创建的文件日期以下是用于获取图像列表的方法,
public static String[] getAllImages(){
String[] rootFolders = MainActivity.getStorageDirectories();
if (rootFolders == null)
{
return rootFolders;
}
int rl = rootFolders.length;
for (int i = 0; i < rl; i++)
{
String path = rootFolders[i];
File target = new File(path + "/DCIM/Camera/");
if (target.exists())
{
File[] filelists = target.listFiles();
if(common==null)
common = new ArrayList<File>(Arrays.asList(filelists));
else
Collections.addAll(common, filelists);
}
File target2 = new File(path + "/DCIM/100ANDRO/");
if (target2.exists())
{
File[] filelist = target2.listFiles();
if(common == null)
common = new ArrayList<File>(Arrays.asList(filelist));
else
Collections.addAll(common, filelist);
}
}
int i = common.size();
String[] list = new String[i];
int counter = 0;
String name = null;
String path = "file:///";
for(File file : common)
{
date = new Date(file.lastModified());
if(file.isFile())
name = path+file.getAbsolutePath().toString();
list[counter] = name;
mThumbIds = new Integer[counter];
counter++;
}
return list;}
和getview()方法显示图像,
String[] imagesurl = getAllImages();
public View getView(int position, View convertView,
ViewGroup parent) {
View view = convertView;
final ViewHolder gridViewImageHolder;
if (convertView == null) {
view = getLayoutInflater().inflate(R.layout.item_grid_image, parent, false);
gridViewImageHolder = new ViewHolder();
gridViewImageHolder.imageView = (ImageView) view.findViewById(R.id.image);
gridViewImageHolder.imageView.setMaxHeight(80);
gridViewImageHolder.imageView.setMaxWidth(80);
view.setTag(gridViewImageHolder);
} else {
gridViewImageHolder = (ViewHolder) view.getTag();
}
imageLoader.displayImage(imagesURL[position], gridViewImageHolder.imageView,options);
return view;
}
提前致谢。