How can we create dynamic textview?

前端 未结 6 1672
故里飘歌
故里飘歌 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:42

    private LinearLayout ll;
    private TextView tv;
    
    
          // in oncreate()
    onCreate()
    {
            int WrapWidth = LinearLayout.LayoutParams.WRAP_CONTENT;
            int WrapHeight = LinearLayout.LayoutParams.WRAP_CONTENT;
    
            tv = new TextView(this);
    
            ll.addView(tv,WrapWidth,WrapHeight);
    
    
    }
    

提交回复
热议问题