开发者

How to check if two EditText contain text

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)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜