且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从其他变量值做变量名

更新时间:2023-01-08 08:07:31

我相信你想实现这个样的例子。

I am sure you want to implement this kind of example.

当你想实现findViewById()在循环中当有与就像反varialbe 1,2,3,4,5等。

This is helpful when you want to implement findViewById() inside a loop when there are many number of views with just a difference like "counter" varialbe 1, 2,3,4,5,etc.

for(int i=0; i<15; i++) 
{
    String imageID = "img" + (i);
    int resID = getResources().getIdentifier(imageID, "drawable", getPackageName());

  /* if you want to reference any widgets like Button, TextView, ImageView, etc. then write below code:

    //int resID = getResources().getIdentifier(imageID, "id", getPackageName());   
  */
}