简体   繁体   English

当其他人编辑文本值更改时更改编辑文本值

[英]change edit text value when others edit text value change

This is what I'm doing这就是我正在做的

binding.etReceivedPrice.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                Price = binding.etTotalPrice.getText().toString();
                Received = binding.etReceivedPrice.getText().toString();

                totalAmount =  Integer.parseInt(Price) - Integer.parseInt(Received) ;

                binding.etTotalAmount.setText(totalAmount);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

I want to calculate total amount and display in total amount edit text when received amount is typed.我想在输入收到的金额时计算总金额并在总金额编辑文本中显示。

You're binding integer value.您正在绑定整数值。 When you bind integer value it won't show compile time error because string file values are integer only.当您绑定整数值时,它不会显示编译时错误,因为字符串文件值只是整数。

Bind like this.像这样绑定。

binding.etTotalAmount.setText(String.valueOf(totalAmount));

One more suggestion use camelCase for your variables like "totalAmount"另一项建议是使用 camelCase 作为变量,例如“totalAmount”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM