I have two EditText and one Button in my Layout. If the two EditText both contain a text, i want to enable the button:
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
System.out.println("Key input");
String usr = user.getText().toString();
String pw = password.getText().toString();
if ( (!usr.equals("")) && (!pw.equals(""))) {
ok.se开发者_开发问答tEnabled(true);
} else {
ok.setEnabled(false);
}
return true;
}
So i tried to register several listeners on the EditText fields:
user.setOnKeyListener(focusListener);
password.setOnKeyListener(focusListener);
Unfortunately, the onKeyListener does not seem to work at all. So i also tried the FocusChangedListener and the ActionListener. But none of them provided the behaviour i'd like.
Any hints how to implement that?
Take a look at http://developer.android.com/reference/android/widget/TextView.html#addTextChangedListener(android.text.TextWatcher)
精彩评论