switch 语句不进行切换

发布于 2024-12-21 22:14:49 字数 1151 浏览 2 评论 0原文

我正在尝试使用微调器更改 switch 语句中变量的值。但该变量停留在默认值上。 这是带有 switch 语句的代码,以及如何使用该变量。

    final Spinner feedbackSpinner = (Spinner) 
    findViewById(R.id.SpinnerFeedbackType);  

    String RSSFEEDOFCHOICE;
    switch((int)feedbackSpinner.getSelectedItemId())  {      
         case R.string.groep1:
        RSSFEEDOFCHOICE = "https://www.scouting.nl/publiek/nieuws?format=feed&type=rss";
         break;
         case R.string.groep2:
        RSSFEEDOFCHOICE = "https://www.scouting.nl/publiek/nieuws?format=feed&type=rss";
         break;
         case R.string.groep3:
        RSSFEEDOFCHOICE = "https://www.scouting.nl/publiek/nieuws?format=feed&type=rss";
         break;
         case R.string.groep4:
        RSSFEEDOFCHOICE = "https://www.scouting.nl/publiek/nieuws?format=feed&type=rss";
             break;
         default:           
             RSSFEEDOFCHOICE = "http://www.scout.org/rss/feed/all";
             break;
     }


    // get rss feed
    feed = getFeed(RSSFEEDOFCHOICE);

    UpdateDisplay();
        }

private RSSFeed getFeed(String urlToRssFeed)

我只是不明白为什么 RSS 提要没有改变,而变量应该改变了。

I'm trying to change the value of a variable in a switch statement, with a spinner. But the variable is stuck on the default value.
Here's the code with the switch statement, and how the variable is used.

    final Spinner feedbackSpinner = (Spinner) 
    findViewById(R.id.SpinnerFeedbackType);  

    String RSSFEEDOFCHOICE;
    switch((int)feedbackSpinner.getSelectedItemId())  {      
         case R.string.groep1:
        RSSFEEDOFCHOICE = "https://www.scouting.nl/publiek/nieuws?format=feed&type=rss";
         break;
         case R.string.groep2:
        RSSFEEDOFCHOICE = "https://www.scouting.nl/publiek/nieuws?format=feed&type=rss";
         break;
         case R.string.groep3:
        RSSFEEDOFCHOICE = "https://www.scouting.nl/publiek/nieuws?format=feed&type=rss";
         break;
         case R.string.groep4:
        RSSFEEDOFCHOICE = "https://www.scouting.nl/publiek/nieuws?format=feed&type=rss";
             break;
         default:           
             RSSFEEDOFCHOICE = "http://www.scout.org/rss/feed/all";
             break;
     }


    // get rss feed
    feed = getFeed(RSSFEEDOFCHOICE);

    UpdateDisplay();
        }

private RSSFeed getFeed(String urlToRssFeed)

I just don't get why the RSS feed doesn't change, while the variable should have changed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小清晰的声音 2024-12-28 22:14:49

R.String。将返回资源的 ID,而不是 strings.xml 中的字符串,因此比较将失败。您可能想改用 getString(R.string.hello) 并删除 switch 语句中对 int 的类型转换。

R.String. would return the ID of the resource and not the string which is inside your strings.xml therefore the comparison would fail. You might want to use getString(R.string.hello) instead and remove the typecasting to int in the switch statement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文