how to make the button unClickable if EditText is empty
As other answers said :
if(edt_text.getText().equals(""))
{
button.setEnabled(false);
}
I have 2 Edit text and a button I don't want the user to be able to click the button if one of the EditText is empty
In this case it would be better to implement addTextChangedListener in order to setEnable(false) the button if EditText is empty, and to true if not.
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
if(s.toString().equals("")) {
button.setEnabled(false);
} else {
button.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
}
});
and I would like to know how to let the button change color to transparent while clicking the button so it looks like you pushed the button
If you are using the default Button style, so you have nothing more to do. But If you define a selector drawable for your button, setEnable() method on the EditText will call the corresponding drawable of android:state_enabled attribute of your selector drawable (if defined).
More info on Selectors here : StateList Drawables