如何在android studio中按下按钮

时间:2017-12-13 00:12:14

标签: android

****我有3个按钮,我想按顺序按下这些按钮 在按下第一个按钮之前,用户无法按下第二个或第三个按钮 并且不能在第二个和第一个按钮之前按下第三个按钮,如果他按下按钮以便他将获胜否则他将失去

和我的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_newgame);
    fox = findViewById(R.id.foxbutton);
    rabbit = findViewById(R.id.rabbitbutton);
    carrot = findViewById(R.id.carrotbutton);
    score = findViewById(R.id.score);

    //declare boolean
    fox.setOnClickListener( this);
    rabbit.setOnClickListener( this);
    carrot.setOnClickListener( this);
    //my button click

}

public void onClick(View v) {
    if (carrot.isPressed()) {
        scorecount++;
        score.setText("socre:" + scorecount);

        if ( rabbit.isPressed()) {
            scorecount++;
            score.setText("socre:" + scorecount);

            if (fox.isPressed()) {
                scorecount++;
                score.setText("socre:" + scorecount);
            }
        }
    }
}

@Override
public void onPointerCaptureChanged(boolean hasCapture) {

}

感谢**

1 个答案:

答案 0 :(得分:0)

你可以使用按钮setEnabled(boolean)的启用/禁用属性; ,并使用isEnabled()继续检查onClick()启用/禁用。