2011-06-06 89 views
0

我想創建多個TextView框動態,如果我在EditText中輸入2,它想創建2個TextView,如果我在EditText中輸入5,它想創建5個TextView等...可以誰能幫我...動態創建TextView框

在此先感謝,

回答

0

首先需要獲取父layout.if是,說的LinearLayout意味着,您可以通過使用addView(視圖)添加TextView的。

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

kulanthai:感謝您UR幫助...我認爲ü來自泰米爾納德邦,印度... – Saran 2011-06-06 09:28:44

+0

是。如果你認爲答案對你有幫助,接受答案河 – Kakey 2011-06-06 09:45:12