I have some code where I need a "Create Account" button to be disabled if an editText field has less than 3 char in it. If the User enters 3 chars, then the button should enable itself so that it can be used.
I have constructed the if else statement that disables the button if there are less than 3 char in the editText field, BUT on input, when the user inserts 3 char, it does not re-evaluate to see if the statement is true so the button of course stays disabled.
Once the user enters 3 char into the edit text field, the button should enable itself.
Button buttonGenerate = (Button) findViewById(R.id.btnOpenAccountCreate);
userInitials = (EditText) findViewById(R.id.etUserChar);
if (userInitials.getText().toString().length() > 3) {
// Account Generator Button
buttonGenerate.setEnabled(true); // enable button;
buttonGenerate.setOnClickListener(new OnClickListener() {
//Do cool stuff here
@Override
public void onClick(View v) {
}
});// END BUTTON
} else {
// If UserInitials is empty, disable button
Toast.makeText(this, "Please enter three(3) characters in the Initials Field ", Toast.LENGTH_LONG)
.show();
buttonGenerate.setEnabled(false); // disable button;
}// END IF ELSE