I want to create a button which is disabled. Only way to enable it if user inputs correct details and after the user clicks submit, if the details provided is correct, the button is enabled to go further.
Asked
Active
Viewed 831 times
0
-
1by disabled as in its invisible or is it the same button as the submit button? – Shivansh Potdar Jul 26 '20 at 09:21
-
2Does this answer your question? [How to disable an Android button?](https://stackoverflow.com/questions/4384890/how-to-disable-an-android-button) – Javad Dehban Jul 26 '20 at 11:40
3 Answers
1
set this property on initializing the button in your class
button.setClickable(false); // by default it is disable
put this code in your submit button onClickListenser to check input validity eg
if(validateUserInput()) //check for the validation of your logic in a fuction
button.setClickable(true);
else
button.setClickable(false);
function validateUserInput
private boolean validateUserInput(){
//your logic here for validation
if(your check)
return true;
else
return false;
}

Sultan
- 119
- 1
- 12
0
Use these lines where you need to make button disabled or enabled.
button.isEnabled=false
OR
button.isEnabled=true

MMG
- 3,226
- 5
- 16
- 43
0
You can disable it on code with Button.setEnabled(false); then later you you can turn it on when the submit button is pressed with Button.setEnabled(true);

Talha
- 9
- 2