如何在Android Studio上解决这个问题?

时间:2016-09-03 12:00:32

标签: android android-layout android-studio

点击黄色按钮5次,点击红色按钮2次,绿色按钮3次。如果成功完成,请转到下一个测验的下一个屏幕。

1 个答案:

答案 0 :(得分:1)

假设您的按钮已连接到Android Manifest中的相应功能

private int redClicks = 0;
private int greenClicks = 0;
private int yellowClicks = 0;

    public void redClickCount(View view) {

        if (redClicks < 2){
            redClicks++;
        }
        greenClicks = 0;
        yellowClicks = 0;

    }

    public void greenClickCount(View view) {

        if (redClicks == 2 && greenClicks < 3){
            greenClicks++;
        } else { //start all over again
            redClicks = 0;
            greenClicks = 0;
            yellowClicks = 0;
        }

    }

    public void yellowClickCount(View view) {

        if (redClicks == 2 && greenClicks == 3 && yellowClicks <5){
            yellowClicks++;
        } else { 
            if (redClicks == 2 && greenClicks == 3 && yellowClicks = 5){
                // go to next round
            } else {
                //start all over again
                redClicks = 0;
                greenClicks = 0;
                yellowClicks = 0;
            }
        }    
    }