[英]Switch statements aren't recognized
I try to read the cases of a simple radiogroup. 我尝试阅读一个简单的无线电组的案例。 So instead of showing the selected value via toast (like in a working example), I want so sum the "score" depending on the selected radiobutton.
因此,我不想通过烤面包来显示所选的值(例如在一个工作示例中),而是根据所选的单选按钮求和“分数”。
So the code lines in this area (MainActivity.java) that I tried: 因此,我尝试了该区域中的代码行(MainActivity.java):
public void onClick(View v) {
int selected_id = radio_group_question1.getCheckedRadioButtonId();
radio_button_question1 = (RadioButton)findViewById(selected_id);
switch(radio_group_question1.getId()) {
case R.id.radio_q1_answer1:
score = score + 0;
break;
case R.id.radio_q1_answer2:
score = score + 1;
break;
...
}
...
}
Unfortunately the "score" is always "0" like I initialized in the beginning (int score = 0;). 不幸的是,就像我在一开始就初始化的那样,“分数”始终为“ 0”(int score = 0;)。 :(
:(
Any ideas? 有任何想法吗?
Many thanks and greetings! 非常感谢和问候!
在switch
语句中,您要检查radio_group_question1.getId()
它是整个无线电组的ID radio_group_question1.getId()
,您应该执行以下操作:
switch(selected_id){
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.