android - 在android中使用变量访问XML

标签 android android-xml

我想使用访问图片

image.setImageResource(R.drawable.photo1);

如何将“photo1”更改为“photo”+#(递增数字),以便我可以在迭代中使用它?

最佳答案

int resID = getResources().getIdentifier("photo"+1,"drawable", getPackageName());
image.setImageResource(resID); 

关于android - 在android中使用变量访问XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7760661/

相关文章:

android - 将两个并排的 ImageView 居中

android从url加载图片

android - 使用 Intent 从另一个 Activity 传递后出现错误的值

java - Android Horizo​​ntalScrollView 内容拉伸(stretch)

android - 如何从 layout.xml 中删除默认的 cardview 边框

android - UnknownFormatConversionException : Android strings. xml 格式 <![CDATA[ ...%1$... ]]>

android - 如何在 OpenCV Android 中创建和显示直方图?

android - AccessibilityService 可以调度关键事件,甚至包括 Unicode 字符吗?

android - 平移对象背后的动画

android - 带有圆角、描边和选择器图标的自定义微调器