如何从动态创建的edittexts中获取值(how to get values from dynamically created edittexts)
我创建了一个tablelayout,其中包含动态创建的行,每行有3个edittexts。 假设有5行,每行有3个edittexts,我如何从每行的每个第一个edittext中输入输入的值到arraylits并计算它们。
这是我到目前为止的代码:
Public void addRow (View v) { TableRow row = new TableRow(this); EditText et1 = new EditText(this); EditText et2 = new EditText(this); EditText et3 = new EditText(this); idCount++; mRowCount++; et1.setTag(a + idCount); et1.setText(a + idCount); et2.setTag(b + idCount); et2.setText(b + idCount); et3.setTag(c + idCount); et3.setText(c + idCount); mLayout.addView(row); row.setId(mRowCount); row.addView(et1); row.addView(et2); row.addView(et3);提前完成
I have created a tablelayout with dynamically created rows with 3 edittexts on every row. Say there are 5 rows with 3 edittexts on each, how can i get the the entered values from every first edittext from each row into an arraylits and calculating them.
Here is my code so far:
Public void addRow (View v) { TableRow row = new TableRow(this); EditText et1 = new EditText(this); EditText et2 = new EditText(this); EditText et3 = new EditText(this); idCount++; mRowCount++; et1.setTag(a + idCount); et1.setText(a + idCount); et2.setTag(b + idCount); et2.setText(b + idCount); et3.setTag(c + idCount); et3.setText(c + idCount); mLayout.addView(row); row.setId(mRowCount); row.addView(et1); row.addView(et2); row.addView(et3);Thanx in advance
最满意答案
ArrayList<String> stringList = new ArrayList<String>(); //Generic ArrayList to Store your Strings stringList.add(et1.getText()) ;//do this for your 3 textviews stringList.add(et2.getText()) ; stringList.add(et3.getText()) ; int count=0; Iterator<String> iterator = stringList.iterator(); while (iterator.hasNext()) { count=count+Integer.parseInt(iterator.next()); } ArrayList<String> stringList = new ArrayList<String>(); //Generic ArrayList to Store your Strings stringList.add(et1.getText()) ;//do this for your 3 textviews stringList.add(et2.getText()) ; stringList.add(et3.getText()) ; int count=0; Iterator<String> iterator = stringList.iterator(); while (iterator.hasNext()) { count=count+Integer.parseInt(iterator.next()); }更多推荐
row,et,edittexts,arraylits,addView,电脑培训,计算机培训,IT培训"/> <meta name=
发布评论