try {
Class<drawable> res = R.drawable.class;
if(str!=null){
Field field = res.getField(str);
int drawableId = field.getInt(null);
bengalidaypng.setImageResource(drawableId);
}
}
catch (Exception e) {
System.out.println("Image not found in drawable folder");
}
You can take the images in your resource folder. After that follow this simple code:
try {
Class<drawable> res = R.drawable.class;
if(str!=null){
Field field = res.getField(str);
int drawableId = field.getInt(null);
bengalidaypng.setImageResource(drawableId);
}
}
catch (Exception e) {
System.out.println("Image not found in drawable folder");
}
发布评论
评论(3)
您可以使用 类型化数组 资源。链接末尾有一个示例,说明如何将其用于可绘制对象(图像)。
编辑:
资源可以作为原始数据访问:使用AssetManager.open(..)
然后你可以使用 BitmapFactory.decodeStream(. .) 从数据流创建位图。
You could use Typed Array resource. There is an example at the end of the link how to use it for drawables (images).
Edited:
Resources can be accessed as raw data: use AssetManager.open(..)
Then you can use BitmapFactory.decodeStream(..) to create a Bitmap from the data stream.
您可以在资源文件夹中获取图像。之后遵循这个简单的代码:
可以找到更详细的示例 这里。
You can take the images in your resource folder. After that follow this simple code:
A more detailed sample can be found here.
您可以将图像存储到数据库中,然后 当您绑定每一行时,将图像拉入 ListView。
You could store the images into a database, then pull the images into the ListView when you are binding each row.