what is the event when and edittext is updated?

2019-07-23 15:33发布

问题:

I have and android layout with two edittexts one for Qty and one for rate and a textview for total amount. now what i want to do is change/update the total amount whenever the user changes the rate or quantity fields.

what is the edittext event i am looking for and can i set it from the layout xml properties like i can set OnClick?

回答1:

For this You have to set addTextChangedListener() to editText.Just as below


editText.addTextChangedListener(this);// your activity has to implement TextWatcher interface

than you have to override this method


@Override
    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub

    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub

    }

you can use any of this method as ur need and change ur relevant views text