如何从动态创建的edittexts中获取值(how to get values from dynamically created edittexts)

编程入门 行业动态 更新时间:2024-10-11 15:17:55
如何从动态创建的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=

本文发布于:2023-07-14 19:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1106715.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动态   edittexts   values   dynamically   created

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!