开发者

Dynamically creates TextView boxes

I want to create multiple TextView boxes dynamically, If i enter 2 in the Edittext it wants to create 2 TextView, If i enter 5 in the EditText it wants to create 5 TextView and so on... can anyone help me...

Tha开发者_Python百科nks in advance.,


first you need to get the parent layout.if it is ,say LinearLayout means,you can add the textview by using addView(view).

letterTextView = new TextView[length];
for (int Index = 0; Index < length; Index++) 
        {
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            layoutParams.setMargins(0, 0, 25, 0);
            letterTextView[Index] = new TextView(FriendsPanel.this);
            letterTextView[Index].setTextSize(20);
            letterTextView[Index].setTextColor(Color.WHITE);
            letterTextView[Index].setText("TextView"+letterIndex);

            linearLayout.addView(letterTextView[Index], layoutParams);
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜