组单选按钮

时间:2011-08-02 09:39:46

标签: android radio-group

我在组中有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);


                }


            }

        });   

http://i.stack.imgur.com/c9bqe.jpg

1 个答案:

答案 0 :(得分:0)

  1. 无需致电radiogroup1 = (RadioGroup) findViewById(R.id.radioGroup1);

  2. 正确检查单选按钮的ID,因为您的代码没有显示错误,

  3. 发布异常然后我就可以检查id出了什么问题?

相关问题