jeudi 22 septembre 2016

I am needing help in Java for when I use an if statements for an OnClick method

My code snip it is this. I am working on a sport scoring (baseball) app in Android. My code works for each button click so after one click with my strikes button the strike textview in my xml displays a 1. Then after a second click display 2. After a third click the strikes reset to 0 and my outs textview becomes a 1. Same for all the way for out 2.My problem is that when the strikes for the team equals 2 and my Outs for the team equals 2, on next button click the out's on my xml text view shows a 3. After another strike click the 3 resets back to a 0. While that is technically correct, I want it to when it displays a 2 strikes and 2 outs on next strike button click to reset the strikes and outs back to all zeros. Any help appreciated. Thank you.

 // Find the Button that shows the increment strike button for team A.
    final Button baseballAStrikePlus = (Button) findViewById(R.id.increment_a_strike);
    // Set a click listener on that View
    baseballAStrikePlus.setOnClickListener(new View.OnClickListener() {
        // The code in this method will be executed when the category is clicked on.
        @Override
        public void onClick(View view) {
            if (teamAOuts == 3) {
                teamAOuts = 0;
                outsForTeamA(teamAOuts);
                return;

            } else {
                if (teamAStrikes == 2) {
                    teamAOuts = teamAOuts + 1;
                    outsForTeamA(teamAOuts);
                    teamAStrikes = 0;
                    strikesForTeamA(teamAStrikes);
                    return;
                }
            }
            teamAStrikes = teamAStrikes + 1;
            strikesForTeamA(teamAStrikes);
        }
    });

Aucun commentaire:

Enregistrer un commentaire