android - 在 Android 的 ImageView 中加载图像

标签 android android-widget imageview

在我的应用程序中....有一些图像,例如 temp1.jpg、temp2.​​jpg .....upto temp35.jpg,

所以在单击按钮时,我想在 ImageView 中加载一张一张的图像.... 我想这样做:

cnt=1;
imagename="temp" + cnt + ".jpg";
cnt++;

所以我的困惑是“无论如何都可以从 temp1.jpg 等字符串(图像名称变量)在 imageview 中加载图像。”

最佳答案

你可以试试这个:

int cnt = 1;
//Bitmap bitmap = BitmapFactory.decodeFile("temp" + cnt + ".jpg");
int imageResource = getResources().getIdentifier("drawable/temp" + cnt + ".jpg", null, getPackageName());
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), imageResource);
imageView.setImageBitmap(bitmap);
cnt++;

希望这就是您要找的。

关于android - 在 Android 的 ImageView 中加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3193356/

相关文章:

java - 像主屏幕中的 facebook Messenger 一样的小部件

java - ImageView 不旋转

android - 在运行时显示图像和文本,android?

android - AlertDialog vs Spinner vs ListView

android - ImageView - 如何以编程方式膨胀或添加?

android - 使用 Android Camera 进行图像处理

Java 如何通过打开图像来启动myapp?

android应用程序直接使用android设备中保存的帐户凭据登录

android - 仅在 android 4.1 上的 android mediaplayer 中的异常 0x80000000

android - 小工具 : Activity automatically launched without onclick()