Android --- 18 --- RadioButton radio button
MainActivity. java:
Import android. app. activity; import android. OS. bundle; import android. view. menu; import android. view. menuItem; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. compoundButton; import android. widget. radioButton; import android. widget. radioGroup; import android. widget. toast; import android. widget. compoundButton. dependencies;/*** RadioButton * @ author Caesar **/public class MainActivity extends Activity implements OnClickListener {private Button button; private RadioGroup group; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); group = (RadioGroup) this. findViewById (R. id. sex); button = (Button) this. findViewById (R. id. button); button. setOnClickListener (this) ;}@ Overridepublic void onClick (View v) {// TODO Auto-generated method stub // obtain the number of options in the single-choice button group int len = group. getChildCount (); String msgsString =; for (int I = 0; I <len; I ++) {RadioButton radioButton = (RadioButton) group. getChildAt (I); if (radioButton. isChecked () {msgsString = radioButton. getText (). toString (); break;} Toast. makeText (MainActivity. this, msgsString, 1 ). show ();}}