Reputation: 465
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
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
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
Reputation: 3444
You can try to put your images in drawable folder under /res. Use an ImageAdapter
that extend BaseAdapter
to populate your ListView. You can use this code : http://www.java2s.com/Code/Android/2D-Graphics/extendsBaseAdaptertocreateImageadapter.htm
Upvotes: 0
Reputation: 40416
put your image in drawable folder and set so imageview...
resourceIdView.setImageResource(R.drawable.AUD);
Upvotes: 1