switch 语句不进行切换
我正在尝试使用微调器更改 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.