This article uses radiogroup and radiobutton to implement Single-Choice of intra-group information,
Radiogroup groups radiobutton for the same management and control.
At the same time, the default value is also obtained.
The specific example is as follows: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + MS5hY3Rpdml0eV9tYWluLnhtbDwvcD4KPHA + PHByZSBjbGFzcz0 = "brush: java;">
2. strings. xml
RadioGroupDemo
Select your gender:
Settings
Male
Female
3. MainActivity. java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); defaultStr = this.getResources().getString(R.string.please_selected); seletedTv = (TextView) this.findViewById(R.id.diplay_seleted_item_tv); sexRg = (RadioGroup) this.findViewById(R.id.sex_rg); manRb = (RadioButton) this.findViewById(R.id.man_rb); womanRb = (RadioButton) this.findViewById(R.id.woman_rb); manRb.setChecked(true); seletedTv.setText(defaultStr + manRb.getText().toString()); sexRg.setOnCheckedChangeListener(new OnCheckedChangeListener(){@Overridepublic void onCheckedChanged(RadioGroup rg, int checkedId) {// TODO Auto-generated method stubif(checkedId == manRb.getId()){seletedTv.setText(defaultStr + manRb.getText().toString());}else if(checkedId == womanRb.getId()){seletedTv.setText(defaultStr + womanRb.getText().toString());}else{seletedTv.setText(defaultStr);}} }); }