How do I iterate through the id properties of R.java class?

前端 未结 3 1673
有刺的猬
有刺的猬 2020-12-01 15:26

I\'ve 16 textViews and need to set something like this done:

for (int i=1; i<6; i++)
{
    int $RidInt = R.id.s; 
    tv[i] = (TextView)findViewById($RidI         


        
3条回答
  •  眼角桃花
    2020-12-01 15:35

    try this.

    public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
    
                setContentView(R.layout.main);
                LinearLayout ll = (LinearLayout) findViewById(R.id.LinearLayout01);
                for (int i = 0; i < ll.getChildCount(); i++) {
                    ((TextView) ll.getChildAt(i)).setText("Text View " + i);
                }
    

提交回复
热议问题