Zuni Butt Zuni Butt - 3 months ago 7
Android Question

How to solve this scenario on Android Studio?

Click on red button 2 times and green button 3 times after this click on yellow button 5 times. If this done successfully you go on next screen for next quiz.

Answer

Assuming your buttons already connected to corresponding functions in 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;
            }
        }    
    }