Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Last active March 23, 2021 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/0b0fef6399bfe4369363cf5dd20f1605 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/0b0fef6399bfe4369363cf5dd20f1605 to your computer and use it in GitHub Desktop.
【Android Studio】画像名を使って ImageView に画像を表示する方法
// ImageViewの用意
ImageView myImage= findViewById(R.id.myImage);
// 画像名
String imageName = "sample";
// 画像のリソースIDを取得
int resId = getResources().getIdentifier(imageName, "drawable", getPackageName());
// ImageViewに画像をセット
myImage.setImageResource(resId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment