代码下载链接:http://download.csdn.net/detail/a123demi/7511835
本文将通过radiogroup和radiobutton实现组内信息的单选,
当中radiogroup就是将radiobutton进行分组,同一管理和控制
同一时候实现默认选中情况,获取默认值.效果图
详细实比例如以下:
1.activity_main.xml
2.strings.xml
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(){ @Override public void onCheckedChanged(RadioGroup rg, int checkedId) { // TODO Auto-generated method stub if(checkedId == manRb.getId()){ seletedTv.setText(defaultStr + manRb.getText().toString()); }else if(checkedId == womanRb.getId()){ seletedTv.setText(defaultStr + womanRb.getText().toString()); }else{ seletedTv.setText(defaultStr); } } }); }