2015-10-13 93 views
0

嗨,我有一些drawables,我通过开关运行。安卓在动态绘图

是否可以在for语句中运行这些语句?

喜欢的东西...

I = 0;

String d =“tab”+ i;

R.drawable。[d];

i ++;

感谢 艾丹

+0

可以使用[则getIdentifier(HTTP:// stackoverflow.com/questions/28772290/how-to-add-string-in-int-r-string-nameinteger-parsemyindex-not-working) – Blackbelt

回答

0

是的,你可以做这样的事情:

String d = "tab"+i; 

int id = getActivity().getResources().getIdentifier(d, 
       "drawable", getActivity().getPackageName()); 

然后设置你的形象:

yourImageView.setImageResource(id); 
+0

增加可爱。非常感谢 – aidanmack