Siva K
Siva K

Reputation: 4968

how to disable a button in an android app

in my app i have three buttons namely A,B and C. I want the buttons B and C to be disabled until button A is clicked. they should be ready to perform this function until button A is clicked how to do this.....

Upvotes: 1

Views: 2290

Answers (4)

Ramkumar
Ramkumar

Reputation: 91

Disable the button

myButton.setEnabled(false);

Enable the button

myButton.setEnabled(true);

Upvotes: 0

Shaun Dubuque
Shaun Dubuque

Reputation: 236

// assuming valid references to buttons
buttonB.setEnabled(false);
buttonC.setEnabled(false);

buttonA.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
    buttonB.setEnabled(true);
    buttonC.setEnabled(true);
}
});

Upvotes: 1

Rajath
Rajath

Reputation: 11946

protected void onCreate(Bundle savedInstanceState)
{
    buttonB.setEnabled(false);
    buttonC.setEnabled(false);
}

public void onClick(View v)
{
    if (v == buttonA)
    {
        buttonB.setEnabled(true);
        buttonC.setEnabled(true);
    }
}

Upvotes: 3

Robin
Robin

Reputation: 10011

you should write this will creating your app

myButton.setEnabled(false);

and in the button click function you should enable it by doing this.

myButton.setEnabled(true);

Upvotes: 3

Related Questions