tags:

views:

50

answers:

1

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.setEnabled(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?

+2  A: 

Take a look at http://developer.android.com/reference/android/widget/TextView.html#addTextChangedListener(android.text.TextWatcher)

Asahi
Thanks. This helped a lot!
Roflcoptr