【问题标题】:Getting an ID of checked RadioButton in Android在 Android 中获取选中的 RadioButton 的 ID
【发布时间】:2012-07-11 17:08:46
【问题描述】:

我的 XML 文件中有一个带有 3 个 RadioButton 和一个 Button 的 RadioGroup。当我点击按钮时,如何获取选中的 RadioButton 的 ID(我为此按钮设置了 OnClickListener)?稍后我想在 onClick 中使用 Switch 语句,在检查了哪个 RadioButton 被选中之后。

谢谢!

【问题讨论】:

    标签: android radio-button onclicklistener radio-group


    【解决方案1】:

    你可以用这个

    yourRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    // TODO Auto-generated method stub
    
                }
            });
    

    【讨论】:

      【解决方案2】:

      在您的 RadioGroup 上使用 getCheckedRadioButtonId()

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-06-09
        • 2016-08-14
        • 1970-01-01
        • 1970-01-01
        • 2018-03-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-16
        相关资源
        最近更新 更多