开发者

ontextchange android

开发者 https://www.devze.com 2023-02-24 12:47 出处:网络
I need the method or the action when the EditText change开发者_如何学编程d. When the user write in EditText I want to have some action. How to do that?You can use View.setOnKeyListener(), see here.The

I need the method or the action when the EditText change开发者_如何学编程d. When the user write in EditText I want to have some action. How to do that?


You can use View.setOnKeyListener(), see here.


There are three methods you can register

beforeTextChanged
onTextChanged
afterTextChanged

Example reference: Counting Chars in EditText Changed Listener


I always do it with a TextWatcher, and overriding the afterTextChanged like this:

mEditText.addTextChangedListener(new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { }

    @Override
    public void afterTextChanged(Editable editable) {
        String newText = editable.toString();
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消