vikifor
vikifor

Reputation: 465

Can't see image in ImageView android

I am trying to populate ListView Item with an object from MyClass. One of the property of the class is jpg image. I put my images in images/ folder. I use this code for populating

private static final String ASSETS_DIR = "images/";
String imgFilePath=ASSETS_DIR+r.resourceID;

    try{
    Bitmap bitmap = BitmapFactory.decodeFile(imgFilePath);
    resourceIdView.setImageBitmap(bitmap);


    }
    catch(Exception e)
    {
        System.out.println(" Error");

    }

r.resourceID is the name of the image for example "AUD.jpg" resourceIDView is ImageView The program don't get in the catch part, however I can't see the image could somebody help me??

Upvotes: 2

Views: 1648

Answers (4)

Peter Arandorenko
Peter Arandorenko

Reputation: 196

What I had was that the image was showing in Designer but not on device, so I put the image in all the drawable-xdpi directories. This worked for me.

Upvotes: 0

Arun George
Arun George

Reputation: 18592

From your naming convention I conclude that you are storing your images in the "assets" folder. If yes, then you can use the following lines of code and get this issue resolved:

private static final String ASSETS_DIR = "images/";
String imgFilePath=ASSETS_DIR+r.resourceID;

try{
    Drawable d = Drawable.createFromStream(getAssets().open(imgFilePath), null);
    resourceIdView.setImageDrawable(d);
}
catch(Exception e)
{
    System.out.println(" Error");

}

Hope this helps.

Upvotes: 1

113408
113408

Reputation: 3444

You can try to put your images in drawable folder under /res. Use an ImageAdapterthat extend BaseAdapterto populate your ListView. You can use this code : http://www.java2s.com/Code/Android/2D-Graphics/extendsBaseAdaptertocreateImageadapter.htm

Upvotes: 0

Samir Mangroliya
Samir Mangroliya

Reputation: 40416

put your image in drawable folder and set so imageview...

 resourceIdView.setImageResource(R.drawable.AUD);

Upvotes: 1

Related Questions