使用单选按钮组在 android 工作室中打开新的 activity

using radiobutton group to open new activity in android studio

我有一组 4 个单选按钮 select 按下按钮时 activity 打开,我已经尝试了下面的代码用于其中的 2 个单选按钮,但它无法正常工作故意的。我是 java 的新手,所以任何帮助都会很棒,谢谢!

public class ModeSelect extends ActionBarActivity {



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mode_select);

   // Button OpenChannel = (Button)findViewById(R.id.OpenChannelMode0);
    RadioButton SPIM = (RadioButton)findViewById(R.id.SPIMaster);

    SPIM.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

    Button OpenChannel = (Button)findViewById(R.id.OpenChannelMode0);

    OpenChannel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(ModeSelect.this, SPIOptions.class);
            startActivity(i);
        }
    });
        }
    });

    RadioButton I2CM = (RadioButton)findViewById(R.id.I2CMaster);

    I2CM.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            Button OpenChannel = (Button)findViewById(R.id.OpenChannelMode0);

            OpenChannel.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent i = new Intent(ModeSelect.this, I2COptions.class);
                    startActivity(i);
                }
            });

        }
    });
}

以这种方式尝试

 Button OpenChannel = (Button)findViewById(R.id.OpenChannelMode0);

    OpenChannel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if(radiobuttonObj1.isChecked()){
                //open activity 1
            }else if(radiobuttonObj2.isChecked()){
                //open activity 2
            }

        }
    });