开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜