Answer the question
In order to leave comments, you need to log in
How to trace backspace key?
Hello, I have an EditText field. You can only enter whole numbers in it. I need to activate the button if the length of the entered data is greater than 0 and accordingly block if it is equal to zero.
I am trying to do like this:
editNumberRace = (EditText)findViewById(R.id.editText2);
View.OnKeyListener onKeyListener = new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(editNumberRace.toString().length()>0){
//делаем что то
}
else {
//делаем что то
}
return false;
}
};
editNumberRace.setOnKeyListener(onKeyListener);
Answer the question
In order to leave comments, you need to log in
You don't need to track. You just need to use the right tools. To work with EditText there is a special TextWatcher .
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// 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 afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question