how to disable a button in an android app
in my ap开发者_Python百科p 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.....
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);
}
}
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);
// 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);
}
});
Disable the button
myButton.setEnabled(false);
Enable the button
myButton.setEnabled(true);
精彩评论