Suleman Bajwa
Suleman Bajwa

Reputation: 23

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.

Upvotes: 0

Views: 51

Answers (1)

Gobu CSG
Gobu CSG

Reputation: 691

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"

Upvotes: 1

Related Questions