RaidoButton单选框
应用场景:实现单选效果 eg:问卷调查 性别选中
xml:
RadioButton
android:checked="true" 设置是否 选中
android:text="RadioButton" 文本
注意:
RaidoButton要实现单选效果必须放在RadioGroup中
RadioGroup设置方向:
android:orientation="horizontal" 水平
code:
//获得RadioGroup
RadioGroupmGroup=(RadioGroup)findViewById(R.id.radioGroup1);
//获得被选中的RadioButtonId
intcheckedRadioButtonId=mGroup.getCheckedRadioButtonId();
//查找选中的RadioButton
RadioButtonbutton=(RadioButton)findViewById(checkedRadioButtonId);
//获得选中的RadioButton的文本
Stringstring=button.getText().toString();
//设置RadioButton状态改变监听事件
mGroup.setOnCheckedChangeListener(newOnCheckedChangeListener(){
@Override
publicvoidonCheckedChanged(RadioGroupgroup,intcheckedId){
//获得被选中的RadioButton
RadioButtonbutton=(RadioButton)findViewById(checkedId);
//获得选中的RadioButton的文本
Stringstring=button.getText().toString();
mTv.setText(string);
}
});
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。