Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android studio中按按钮_Android - Fatal编程技术网

如何在android studio中按按钮

如何在android studio中按按钮,android,Android,****我有3个按钮,我想按顺序按下这些按钮 在按下第一个按钮之前,该用户不能按下第二个或第三个按钮 不能在第二个和第一个按钮之前按下第三个按钮,如果他按下按钮是为了赢,否则他会输 我的代码是: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_newgame);

****我有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) {

}

谢谢**

您可以使用按钮setEnabledboolean;的启用/禁用属性,然后继续检查,单击使用isEnabled启用/禁用的。

您的问题是什么?你的代码有效吗?如果没有,它会做什么?你期望它做什么?是的,不清楚你的意思。您当然可以禁用按钮,即当按下按钮时,不会发生任何事情,也不会显示任何按下的动画。