-1

I have made a simple switch case (never used on before...so bear with me).

        select_diff.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
        @Override
        public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
            rating = (int)(select_diff.getRating() * 10);
            Toast.makeText(timestables.this, Integer.toString(rating) , Toast.LENGTH_SHORT).show();

            switch (rating) {

                case 10:
                    questions.setText("10 Questions.");
                    time.setText("10 Seconds For Each Question.");
                    timestables.setText("2 to 5 Times Tables");

                case 15:
                    questions.setText("13 Questions.");
                    time.setText("8 Seconds For Each Question.");
                    timestables.setText("2 to 6 Times Tables");

                case 20:
                    questions.setText("15 Questions.");
                    time.setText("7 Seconds For Each Question.");
                    timestables.setText("2 to 7 Times Tables");

                case 25:
                    questions.setText("20 Questions.");
                    time.setText("6 Seconds For Each Question.");
                    timestables.setText("2 to 8 Times Tables");

                case 30:
                    questions.setText("25 Questions.");
                    time.setText("5 Seconds For Each Question.");
                    timestables.setText("2 to 9 Times Tables");

                case 35:
                    questions.setText("30 Questions.");
                    time.setText("4 Seconds For Each Question.");
                    timestables.setText("2 to 10 Times Tables");

                case 40:
                    questions.setText("35 Questions.");
                    time.setText("3 Seconds For Each Question.");
                    timestables.setText("2 to 11 Times Tables");

                case 45:
                    questions.setText("40 Questions.");
                    time.setText("2.5 Seconds For Each Question.");
                    timestables.setText("2 to 12 Times Tables");

                case 50:
                    questions.setText("40 Questions.");
                    time.setText("2 Seconds For Each Question.");
                    timestables.setText("2 to 12 Times Tables");

            }
        }
    });

The variable "rating" is of type INT. The Toast from android always shows the correct case value (i.e. when I select 2 stars...it toasts "20") but the text boxes are not being set...only case 45 (for some reason :S?) seems to ever work...no matter which rating I select.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Jcov
  • 2,122
  • 2
  • 21
  • 32

1 Answers1

1

You need to add break statements at the end of each case to avoid going into every case after the first one it hits.

See this.

Zarwan
  • 5,537
  • 4
  • 30
  • 48