layout.xml MainActivity.java package com.test.radiogroup;import android.os.Bundle;import android.support.annotation.IdRes;import android.support.v7.app.AppCompatActivity;import android.util.Log;import android.widget.RadioGroup;public class
MainActivity.java
package com.test.radiogroup; import android.os.Bundle; import android.support.annotation.IdRes; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.RadioGroup; public class MainActivity extends AppCompatActivity { private RadioGroup rg; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout); rg = (RadioGroup) findViewById(R.id.radioGroup1); rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) { switch (checkedId){ case R.id.radioButton3: Log.i("tag","你选择了男"); break; case R.id.radioButton4: Log.i("tag","你选择了女"); break; default: break; } } }); } }