如何使用Java切换案例

杰科夫

我做了一个简单的开关盒(以前没用过...所以请耐心等待)。

        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");

            }
        }
    });

变量“ rating”的类型为INT。来自Android的Toast始终显示正确的大小写值(即,当我选择2星时,它敬酒“ 20”),但未设置文本框...仅出现大小写45(出于某种原因:S?)无论您选择哪种评级,都可以使用。

扎尔万

您需要在每个案例的末尾添加break语句,以避免在遇到第一个案例后再进入每个案例。

看到这个

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章