天天看点

Android中resource参数变量使用

在Android开发中,经常会用到R.drawable.XXXX来调用资源图片,但这种方式只能直接调用某一个已知名称的资源,如果想动态调用,比如想循环调用图片R.drawable.file1, R.drawable.file2, R.drawable.fileXX等,就不太方便。

如果遇到这种情况,可以用以下代码:

num=1; String iconname="file" + num; int resID=getResources().getIdentifier(iconname, "drawable",  getPackageName()); logo.setImageResource(resID); num++;

转自http://www.cnblogs.com/brucenan/archive/2011/02/10/1950938.html

转载于:https://www.cnblogs.com/mxgsa/archive/2011/02/12/1952729.html