[英]Android : Draw TextEdit(s) or TextView(s) when user enter number of them.[exp: 6 then draw 6 TextView]
想要讓用戶輸入TextEdit或ViewText的數量,然后繪制它們。 例如,用戶輸入7,然后是7個ViewText繪制。我知道這是一種合適的方法,但是由於我無法更改整個結構,因此出現以下錯誤:
tv = new TextView(this);
錯誤是:“未定義構造函數TextView(new View.OnClickListener(){})”。
我知道我必須做:
implements OnClickListener
但是我現在不能更改prgrm.SO無論如何都可以創建TextView(或任何View objct)而無需將其引用為“ layout” xml?
LinearLayout ll = (LinearLayout)findViewById(R.id.myLL);
for(int i=1 ; i<= 10 ; i++){
TextView tv = new TextView(this);
tv.setText("String/String/String");
ll.addView(tv);
}
謝謝,,
您正在向其自身添加LinearLayout。 最后一行應該是ll.addView(tv);
LinearLayout ll = (LinearLayout)findViewById(R.id.myLL);
for(int i=1 ; i<= 10 ; i++)
{
TextView tv = new TextView(getApplicationContext());
tv.setText("String/String/String");
ll.addView(tv);
}
將'new TextView( new )'替換為'new TextView( getApplicationContext() )'。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.