我必須創建n EditText
其中n是用戶輸入。從動態生成的Edittext獲取輸入值
我可以使用for
循環創建它。
TableLayout tbl=(TableLayout)findViewById(R.id.TableLayout1);
//table row
for (int i = 0; i < 5; i++) {
TableRow tr = new TableRow(this);
TableLayout.LayoutParams tableRowParams=
new TableLayout.LayoutParams
(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);
//for set margin
tableRowParams.setMargins(0, 10, 0, 0);
tr.setLayoutParams(tableRowParams);
tr.setGravity(Gravity.CENTER_HORIZONTAL);
//text view
TextView tv=new TextView(this);
tv.setText("Field "+(i+1));
tv.setGravity(Gravity.CENTER);
tv.setTextColor(Color.parseColor("#0070C0"));
tv.setTextSize(26);
tv.setLayoutParams(new TableRow.LayoutParams(100, TableRow.LayoutParams.WRAP_CONTENT));
//add textview
tr.addView(tv);
//set layout params of edittext
TableRow.LayoutParams etParams=
new TableRow.LayoutParams
(120,30);
etParams.setMargins(10, 0, 0, 0);
EditText et=new EditText(this);
et.setLayoutParams(etParams);
et.setBackgroundResource(R.drawable.bg_grey);
et.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
tr.addView(et);
tbl.addView(tr, tableRowParams);
}
我佈局
讓我知道了如何獲取從dymamically創建EditTexts數據。
n次創建循環,在循環中,您可以訪問的EditText輸入的所有文字... – 2015-03-03 07:29:35
如何設置和獲取IDS? – 2015-03-03 07:32:39