How to use addTextChangedListener to change values of other TextViews

At times, the value of one TextView is to be replicated into others as a user types the text. Below illustrates how that can be done. In class MainActivity, variable has been declared for the class as below:

TextInputEditText[] array_yourinterest_rate = new TextInputEditText[12];

Within the onCreate method of MainActivity, addTextChangedListener was added to change the values of the views in array_yourinterest_rate as the value of bindMainly.activityMainMyInterest changes as the user types.

Below is the code segment to illustrate how that was done.

bindMainly.activityMainMyInterest.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) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            for (int i = 0; i < 12; i++) {
                array_yourinterest_rate[i].setText(s.toString());
            }
        }
    });

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s