what is the event when and edittext is updated?

独自空忆成欢 提交于 2019-12-24 06:19:54

问题


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

Then 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 you need and change your relevant views text.



来源:https://stackoverflow.com/questions/4893638/what-is-the-event-when-and-edittext-is-updated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!