-
-
Save codeforfun-jp/0b0fef6399bfe4369363cf5dd20f1605 to your computer and use it in GitHub Desktop.
【Android Studio】画像名を使って ImageView に画像を表示する方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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