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();
}
});
精彩评论