How To Get All The Pictures From The Sdcard Of Emulator And Display It In A Listview?
Solution 1:
This should get you started with it.
http://android-er.blogspot.com/2010/01/android-file-explorer-with-jpgs-exif_08.html
A simple logic to calculate the requirments,
privatevoidgetDir(String dirPath)
{
myPath.setText("Location: " + dirPath);
item = new ArrayList<String>();
path = new ArrayList<String>();
File f = new File(dirPath);
File[] files = f.listFiles();
if(!dirPath.equals(root))
{
item.add(root);
path.add(root);
item.add("../");
path.add(f.getParent());
}
for(int i=0; i < files.length; i++)
{
File file = files[i];
path.add(file.getPath());
if(file.isDirectory())
item.add(file.getName() + "/");
else
item.add(file.getName());
}
ArrayAdapter<String> fileList =
new ArrayAdapter<String>(this, R.layout.row, item);
setListAdapter(fileList);
}
Solution 2:
I haven't tried it, but I suppose if you could be able to create IMageView by putting the images from SD card, you can be able to do this. You can get the images from SD card by creating ContentResolver cursor by passing MediaStore.Images.Media.EXTERNAL_CONTENT_URI and then creating imageview by passing the URI and id (from cursor) to it. After you create ImageView you can create an array of it and pass it to the ArrayAdapter which will then be used to set the data to your ListView. I hope this will help you to solve the problem.
Solution 3:
ArrayList<File> imageReader(File root) {
ArrayList<File> a = new ArrayList<>();
File[] files = root.listFiles();
for(int i=0; i < files.length; i++) {
if(files[i].isDirectory()) {
a.addAll(imageReader(files[i]));
}
else {
if(files[i].getName().endsWith(".jpg")) {
a.add(files[i]);
}
}
}
return a;
}
give your root directory as argument, add all the extensions you want to retrieve.
Post a Comment for "How To Get All The Pictures From The Sdcard Of Emulator And Display It In A Listview?"