Android: How to put an image file from an SD card into a HashMap using a simple adapter?

I am reading files from the selected folder on my phone, as you can see in the following code. And how can I get this working with Imagefile? In the end, I like to have an imagelist with a preview of each image. For instance:

[IMG] (imgview) - [Filename] (String)

for(int i=0; i < files.length; i++) { File file = files[i]; map = new HashMap<String, String>(); if(!file.isHidden() && file.canRead()) { path.add(file.getPath()); if(file.isDirectory()) { map.put("img_list", ""+R.drawable.folder); map.put("string_cell", file.getName()+"/"); your_array_list.add(map); }else{ ImageFileFilter filefilter = new ImageFileFilter(file); if(filefilter.accept(file)){ //Its an imagefile // ==> I like to replace the ""+R.drawable.image with the file that I have read map.put("img_list", ""+R.drawable.image); } else { //Its not an image file } map.put("string_cell", file.getName()); your_array_list.add(map); } } } SimpleAdapter mSchedule = new SimpleAdapter(this, your_array_list, R.layout.connected_upload_row, new String[] {"img_list", "string_cell"}, new int[] {R.id.img_list, R.id.string_cell}); list.setAdapter(mSchedule); 

In the following figure, I like to replace the white image "image" with the original image "41786486733.jpg" as a preview. So that the user can see what picture ...

enter image description here

EDIT FLORIAN PILZ

 if(filefilter.accept(file)){ Log.v("PATH1", file.getPath() ); ImageView myImageView = (ImageView) findViewById(R.id.img_list); Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath()); myImageView.setImageBitmap(bmp); } 

enter image description here

+6
source share
4 answers

The solution for my problem is here:

How to show a sketch from the image path?

I had to create a customlistview (using pรคฯƒsฯั” K) THANKS !!

Create a custom adapter with the extended baseadapter class instead of the SimpleAdapter. since I think it will be easy or you can also create a more user interface instead of using inbuild

0
source

Looking at the image and assuming that the white image with the text โ€œIMAGEโ€ is an instance of ImageView, just ...

 Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath); myImageView.setImageBitmap(bmp); 

Or I completely misunderstood your question. In any case, this little example is trying to do something like what you are trying to accomplish.

+1
source

There is a similar question with the accepted answer. Check: Cannot open image file stored on SD card

Excerpt from there:

 File directory = new File(extStorageDirectory, "myFolder"); File fileInDirectory = new File(directory, files[which]); Bitmap bitmap = BitmapFactory.decodeFile(fileInDirectory.getAbsolutePath()); 
+1
source

You have to implement a custom listview to test this example and apparently keep the path in the problem of creating a hashmap, it will be more useful if you provide a log cat error! Anyway, you can try to perform the trick to achieve the goal, instead of saving the path in hashmap ?, hope this helps you.

 File file = new File(Environment.getExternalStoragePath()+"/Folder/"); file imageList[] = file.listFiles(); for(int i=0;i<imageList.length;i++) { Log.e("Image: "+i+": path", imageList[i].getAbsolutePath()); Bitmap bitmap = BitmapFactory.decodeFile(imageList[i].getAbsolutePath()); myImageView.setImageBitmap(bitmap); 
+1
source

All Articles