关于安卓RadioGroup和RadioButton

RadioGroup是多选按钮布局,里面放至少2个RadioButon,在选择的时候会自动切换显示。

group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
14             
15             @Override
16             public void onCheckedChanged(RadioGroup arg0, int arg1) {
17                 // TODO Auto-generated method stub
18                 //获取变更后的选中项的ID
19                 int radioButtonId = arg0.getCheckedRadioButtonId();
20                 //根据ID获取RadioButton的实例
21                 RadioButton rb = (RadioButton)MyActiviy.this.findViewById(radioButtonId);
22                 //更新文本内容,以符合选中项
23                 tv.setText("您的性别是:" + rb.getText());
24             }
25         });参数arg1是干嘛的
  • arg0 代表触发这个事件的 RadioGroup
  • arg1 表示当前被选中的 RadioButton 的资源 ID。
posted on 2025-06-05 17:27  小沙盒工作室  阅读(17)  评论(0)    收藏  举报