温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

RaidoButton单选框

发布时间:2020-06-30 19:12:34 来源:网络 阅读:375 作者:鹭明 栏目:移动开发

应用场景:实现单选效果    eg:问卷调查  性别选中   

xml:

RadioButton

 android:checked="true"      设置是否     选中 

 android:text="RadioButton" 文本

  注意:

RaidoButton要实现单选效果必须放在RadioGroup中

RadioGroup设置方向:

android:orientation="horizontal"  水平

code:

//获得RadioGroup

RadioGroup mGroup=(RadioGroup) findViewById(R.id.radioGroup1);

//获得被选中的RadioButtonId

int checkedRadioButtonId = mGroup.getCheckedRadioButtonId();

//查找选中的RadioButton

RadioButton button = (RadioButton) findViewById(checkedRadioButtonId);

//获得选中的RadioButton的文本

String string = button.getText().toString();


//设置RadioButton状态改变监听事件

mGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override

            public void onCheckedChanged(RadioGroup group, int checkedId) {

                //获得被选中的RadioButton

                RadioButton button = (RadioButton) findViewById(checkedId);

                //获得选中的RadioButton的文本

                String string = button.getText().toString();

                mTv.setText(string);

            }

        });



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI