Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 无法取消选中动态广播组中已检查的单选按钮大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我第一次设置一个单选按钮,它可以正常工作.但如果我通过调用.setchecked(false)取消选择它;然后,即使我试图通过调用setchecked(true)来选择它也不会取消选择前一个.
private void radiotype() {
    count = //changed every time.
    LinearLayout llques = (LinearLayout) mview.findViewById(R.id.llrbgRBD);
    RadioGroup group = new RadioGroup(context);
    group.setOrientation(RadioGroup.VERTICAL);
    final RadioButton[] rb = new RadioButton[count];
    List<String[]> ans = getAnswerList.getAns();

    for (int j = 0; j < count; j++) {

        rb[j] = new RadioButton(context);
        rb[j].setVisibility(View.VISIBLE);
        rb[j].setText("`enter code here`hi");
        String a = rb[j].getText().toString();`enter code here`
        Log.e("getAnswerList===a","getAnswerList===>a" + a);
        Log.e("getAnswerList","getAnswerList===>" + ans.get(indeX)[0]);
        if (a.equalsIgnoreCase(ans.get(indeX)[0])) {
            rb[j].setchecked(true);
        }
        rb[j].setTextColor(Color.bLACK);
        rb[j].setButtonDrawable(R.drawable.custom_radio_button);
        group.addView(rb[j]);
    }
    llques.removeAllViews();
    llques.addView(group);
    group.setOncheckedchangelistener(new Oncheckedchangelistener() {
        public void oncheckedChanged(RadioGroup group,int checkedId) {
            // checkedId is the RadioButton SELEcted
            //int c = count;
            for(int i=0;i<count;i++){
                rb[i].setchecked(false);
            }
            //
            Log.v("id",""+checkedId);
            for (int i = 0; i < count; i++) {
                if (rb[i].getId() == checkedId){
                    rb[i].setchecked(true);
                } 
            }
        }
    });

解决方法

我知道这已经很老了,但我遇到了同样的问题.解决方案是在通过addView()将RadioButton添加到RadioGroup之后更改其状态.我想这也是BAKUS试图用他的示例代码说的.

大佬总结

以上是大佬教程为你收集整理的android – 无法取消选中动态广播组中已检查的单选按钮全部内容,希望文章能够帮你解决android – 无法取消选中动态广播组中已检查的单选按钮所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。