Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp

codeforfun-jp/MainActivity.java Secret

Last active Mar 23, 2021
Embed
What would you like to do?
【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