Java android代码似乎在使用switch station时出错
我试图对radiobutton使用switch语句,但在运行它时发现错误。谁能帮帮我吗。我已经在下面粘贴了我的android代码。如果你知道答案,请帮忙。非常感谢Java android代码似乎在使用switch station时出错,java,android,Java,Android,我试图对radiobutton使用switch语句,但在运行它时发现错误。谁能帮帮我吗。我已经在下面粘贴了我的android代码。如果你知道答案,请帮忙。非常感谢 package apt.tutorial; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; imp
package apt.tutorial;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.R;
public class LunchtimeActivity extends Activity {
Restaurant r=new Restaurant();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button save=(Button)findViewById(R.id.button1);
save.setOnClickListener(onSave);
}
private View.OnClickListener onSave=new View.OnClickListener() {
public void onClick(View v) {
EditText name=(EditText)findViewById(R.id.text1);
EditText address=(EditText)findViewById(R.id.text2);
r.setName(name.getText().toString());
r.setAddress(address.getText().toString());
RadioGroup types=(RadioGroup)findViewById(R.id.types);
switch (types.GetCheckedRadiobuttonId()) {
case R.id.Sit-Down:
r.setType("Sit_Down");
break;
case R.id.Take-Out:
r.setType("Take_Out");
break;
case R.id.Delivery:
r.setType("Delivery");
break;
}
}
};
}
我认为问题在于:
case R.id.Sit-Down:
case R.id.Take-Out:
将此ID重命名为不带“-”您需要捕获视图中的单选按钮以及单选组
RadioButton sitdown = (RadioButton) findViewByid(R.id.Sit-Down);
等等。我可以看到以下问题:
GetCheckedRadiobuttonId
更改为GetCheckedRadiobuttonId
Sit-Down
是无效的标识符