试试这个:
EditText et1,et2;
Button b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_check);
et1 = (EditText) findViewById(R.id.editText1);
et2 = (EditText) findViewById(R.id.editText2);
b = (Button) findViewById(R.id.button1);
et1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String s1 = et1.getText().toString();
String s2 = et2.getText().toString();
if(s1.equals("") && s2.equals("")){
b.setEnabled(false);
}
else if(!s1.equals("")&&s2.equals("")){
b.setEnabled(false);
}
else if(!s2.equals("")&&s1.equals(""){
b.setEnabled(false);
}
else {
b.setEnabled(true);
}
}
@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
}
});
et2.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String s1 = et1.getText().toString();
String s2 = et2.getText().toString();
if(s1.equals("") && s2.equals("")){
b.setEnabled(false);
}
else if(!s1.equals("")&&s2.equals("")){
b.setEnabled(false);
}
else if(!s2.equals("")&&s1.equals(""){
b.setEnabled(false);
}
else {
b.setEnabled(true);
}
}
@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
}
});
}