How can we create dynamic textview?

前端 未结 6 1722
故里飘歌
故里飘歌 2021-01-21 20:13

how to create the textview in code not in xml file. It is because number of textviews will be changing in my application according to some integer.

6条回答
  •  灰色年华
    2021-01-21 20:54

    Maybe thats what you need:

    LinearLayout lin = (LinearLayout) findViewById(R.id.myLinear);
    
      for (int i = 0; i <= 10 ; i++)
      {
          TextView myText = new TextView(this);
          myText.setText("textview# "+ i);
          lin.addView(myText);
      }
    

提交回复
热议问题