Android findViewbyId with a variant string

后端 未结 1 1663
滥情空心
滥情空心 2020-12-01 19:12
TextView textView1= (TextView) dialog.findViewById(R.id.textView1);

I d like to create something like this:

for (int i=0; i<100;         


        
相关标签:
1条回答
  • 2020-12-01 19:53

    See getIdentifier. Basically, you want something like:

    for (int i=0; i<100; i++) {
       int resId = getResources().getIdentifier("textView" + i, "id", getPackageName());
       TextView textView = (TextView) dialog.findViewById(resId);
    }
    
    0 讨论(0)
提交回复
热议问题