获取ListView中EditText的总值
我想创建演示应用程序来计算列表视图中内容的奖励。 用户可以在 Edittext 中设置数量,我希望从该数量中自动计算所有条目的总和。 目前我在 Edittext 上使用 setOnFocusChangeListener ..但我无法获得完整信息。 请看图片...
有什么建议吗?
谢谢..
I want to create demo app that calculate prize of content in listview.
User can set quantity in Edittext, from that quantity i want auto sum of all imtems.
Currently i have use setOnFocusChangeListener on Edittext.. but i am failed to get tatal.
Please see image...
Any suggestion ?
Thanks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
而不是为每个 EditText 使用
setOnFocusChangeListener
Instead of
setOnFocusChangeListener
use for each EditText在
EditText
上,您可以使用addTextChangedListener(...)
添加一个TextWatcher
。此
TextWatcher
将更改下划线数据并调用适配器上的onDataChanged()
。On the
EditText
, you can add aTextWatcher
withaddTextChangedListener(...)
.This
TextWatcher
will change the underlining data and callonDataChanged()
on the adapter.使用 ListViews
getChildCount()
和getChildAt(i)
获取您的 EditText,然后使用getText()
和总结一下。
希望有帮助。
Use ListViews
getChildCount()
andgetChildAt(i)
to get your EditTexts thengetText()
andsummarize them.
hope it helps.
由于理想情况下您的行是固定的(或不是),否则并不重要。您需要做的就是迭代 ListView 适配器中的每个项目,然后从每个项目中获取文本,然后提取数据。然后跟踪它,并按照您希望的方式处理它。
Since your rows ideally are fixed (or not) either or it does not matter. All you need to do is iterate through each item in your ListView's Adapter and then grab the text from each of them and then extract your data. Then keep track of it, and handle it however you wish to do it.
您可以在每个文本视图上设置 TextWatcher,并在文本更改方法上设置,从每个编辑文本中获取字符串,将值解析为整数,然后添加到总和中。
You can set TextWatcher on each textview, and on text changed method, get string from each edit text, parse value to integer, and add to sum.