我在组中有3个单选按钮,我想点击单选按钮调用意图,但是当我点击单选按钮时,我得到了异常,我无法找出我得到的异常。
这是我的代码。
public class Contentstory extends Activity {
RadioButton Child,Adult,Animated ;
RadioGroup radiogroup1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content);
radiogroup1 = (RadioGroup) findViewById(R.id.radioGroup1);
final RadioButton Child = (RadioButton)findViewById(R.id.radio0);
radiogroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (Child.isChecked()){
Intent intent = new Intent(getApplicationContext(),StoryList.class);
Contentstory.this.startActivity(intent);
}
}
});
答案 0 :(得分:0)
无需致电radiogroup1 = (RadioGroup) findViewById(R.id.radioGroup1);
正确检查单选按钮的ID,因为您的代码没有显示错误,
发布异常然后我就可以检查id出了什么问题?