6

I am reading files from the selected folder on my phone like you can see in the following code. And how could I get this work with an Imagefile? At the end I like to have an imagelist with a preview of every image. Like that:

[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 picture I like to replace the white "image" picture with the original picture called "41786486733.jpg" as preview. So that the user can see what picture this is...

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

Marco Seiz
  • 944
  • 5
  • 19
  • 40
  • You need to implement a custom listview, see an example here [link][1] [1]: http://stackoverflow.com/questions/10267103/add-a-new-item-to-a-listview/10267200#10267200 – pouzzler Dec 07 '12 at 12:32
  • why u are creating HashMap instance two time `map = new HashMap();` remove last one – ρяσѕρєя K Dec 07 '12 at 12:33
  • puzzler i am working with a custon listview ;) ρяσѕρєя every time when you have to reinizialize the HashMap otherwise it's not working... – Marco Seiz Dec 07 '12 at 13:00
  • 1
    @MarcoSeiz : put `map = new HashMap();` after ` File file = files[i];` inside for loop and remove` map = new HashMap();` from every where and plz tell me clearly what is current issue you are phasing – ρяσѕρєя K Dec 07 '12 at 13:05
  • @ρяσѕρєя I added a picutre in my Question for explaining what I want to have. Thanks and cheers :) – Marco Seiz Dec 07 '12 at 13:13
  • @MarcoSeiz : if you want to add images from sdcard as imageview src then first you will need to convert it to Bitmap and then use setImageBitmap for adding to imageview – ρяσѕρєя K Dec 07 '12 at 13:25
  • @MarcoSeiz : see this post http://stackoverflow.com/questions/6224710/set-imageview-to-show-image-in-sdcard – ρяσѕρєя K Dec 07 '12 at 13:27
  • @MarcoSeiz : create an custom adapter by extended baseadapter class instead of SimpleAdapter . as i think this will be easy or also you can create more custom UI instead of using inbuild – ρяσѕρєя K Dec 07 '12 at 13:34
  • It's not working with the Bitmap method... It won't display a picture just the filename and the checkbox. `if(filefilter.accept(file)){ ImageView img = (ImageView) findViewById(R.id.img_list); Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath()); Log.v("PATH", file.getAbsolutePath() ); img.setImageBitmap(bmp); // ==> I like to replace the ""+R.drawable.image with a local image file // map.put("img_list", ""+R.drawable.image); }` – Marco Seiz Dec 07 '12 at 13:53
  • I don't know how to create a custom adapter... DOesn't it work with SimpleAdapter? – Marco Seiz Dec 07 '12 at 13:55
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/20761/discussion-between--k-and-marco-seiz) – ρяσѕρєя K Dec 07 '12 at 15:50
  • @MarcoSeiz : you hve done or still facing same issue – ρяσѕρєя K Dec 07 '12 at 15:52
  • @ρяσѕρєя K The problem still exists... – Marco Seiz Dec 11 '12 at 07:18
  • @MarcoSeiz : what issue you are still facing? – ρяσѕρєя K Dec 11 '12 at 07:46
  • @MarcoSeiz : can you join me on chat http://chat.stackoverflow.com/rooms/20761/discussion-between--k-and-marco-seiz – ρяσѕρєя K Dec 11 '12 at 07:52
  • Answer is here: http://stackoverflow.com/questions/13874644/how-to-show-thumbnail-from-image-path – Marco Seiz Dec 14 '12 at 12:38
  • Problem has been solved. http://stackoverflow.com/questions/13874644/how-to-show-thumbnail-from-image-path – Marco Seiz Dec 18 '12 at 07:22

4 Answers4

1

Looking at the picture, and assuming that the white image with the text "IMAGE" is an ImageView instance, then simply...

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

Or did I completely misunderstood your question. Anyhow this small example tries to do something similar, what your are trying to accomplish.

Florian Pilz
  • 337
  • 1
  • 12
  • This is not working... When I do it with your code the images are empty and it looks like the second picture in my edited answer... – Marco Seiz Dec 12 '12 at 16:11
1

There is a similar question with an answer accepted. Check: Cannot open image file stored in sdcard

Snippet from there:

File directory = new File(extStorageDirectory, "myFolder");
File fileInDirectory = new File(directory, files[which]);
Bitmap bitmap = BitmapFactory.decodeFile(fileInDirectory.getAbsolutePath());
Community
  • 1
  • 1
neteinstein
  • 17,529
  • 11
  • 93
  • 123
1

You have to implement custom listview check this example and seem storing path in hashmap creating issue,it will more helpful if you provide error log cat! anyhow can you try below trick to achieve you goal instead storing path in hashmap?,hope it will help to 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);
RobinHood
  • 10,897
  • 4
  • 48
  • 97
0

the solution for my problem is here:

How to show thumbnail from image path?

I had to create a customlistview (with help from ρяσѕρєя K) THANKS!!

create an custom adapter by extended baseadapter class instead of SimpleAdapter . as i think this will be easy or also you can create more custom UI instead of using inbuild

Community
  • 1
  • 1
Marco Seiz
  • 944
  • 5
  • 19
  • 40