开发者

ontextchange android

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜