gpt4 book ai didi

android - 无法取消选中动态单选组中已选中的单选按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:46:46 25 4
gpt4 key购买 nike

如果我将单选按钮设置为第一次选中,它可以正常工作。但是,如果我通过调用 .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 - 无法取消选中动态单选组中已选中的单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18356874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com