获取ListView中EditText的总值

发布于 2025-01-01 05:17:11 字数 248 浏览 5 评论 0原文

我想创建演示应用程序来计算列表视图中内容的奖励。 用户可以在 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...
enter image description here

Any suggestion ?

Thanks..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

瀞厅☆埖开 2025-01-08 05:17:11

而不是为每个 EditText 使用 setOnFocusChangeListener

addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            totalTextView.setText(getSumOfAll());
        }
    });
}

Instead of setOnFocusChangeListener use for each EditText

addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            totalTextView.setText(getSumOfAll());
        }
    });
}
内心激荡 2025-01-08 05:17:11

EditText 上,您可以使用 addTextChangedListener(...) 添加一个 TextWatcher

TextWatcher 将更改下划线数据并调用适配器上的 onDataChanged()

On the EditText, you can add a TextWatcher with addTextChangedListener(...).

This TextWatcher will change the underlining data and call onDataChanged() on the adapter.

摇划花蜜的午后 2025-01-08 05:17:11

使用 ListViews getChildCount()getChildAt(i) 获取您的 EditText,然后使用 getText()
总结一下。

     int count = listviewview.getChildCount();
     int sum=0;
        for (int i=0; i<count; i++) {

            EditText t = (EditText)((YourLayout)view.getChildAt(i)).getChildAt(1); //1 will get your EditText from the Layout of the List Item because you have 3 children there.
            sum+=Integer.parseInt(t.getText());

        }
return sum*yourprice;

希望有帮助。

Use ListViews getChildCount() and getChildAt(i) to get your EditTexts then getText() and
summarize them.

     int count = listviewview.getChildCount();
     int sum=0;
        for (int i=0; i<count; i++) {

            EditText t = (EditText)((YourLayout)view.getChildAt(i)).getChildAt(1); //1 will get your EditText from the Layout of the List Item because you have 3 children there.
            sum+=Integer.parseInt(t.getText());

        }
return sum*yourprice;

hope it helps.

家住魔仙堡 2025-01-08 05:17:11

由于理想情况下您的行是固定的(或不是),否则并不重要。您需要做的就是迭代 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.

第几種人 2025-01-08 05:17:11

您可以在每个文本视图上设置 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文