【发布时间】:2019-03-25 01:37:22
【问题描述】:
我试试看
radioButton.setChecked(true);
但它唯一有效的第四个单选按钮。我尝试动态创建单选按钮。我在 for 循环中创建单选按钮,然后存储单选按钮值。然后恢复单选按钮的值(也就是说,当我选择第二个选项并保存它然后恢复它时,我有 4 个选项(setChecked 2nd option))但它只有 setChecked 4th 选项。
创建单选按钮。
for (int k = 0; k < choiceElementList.size(); k++) {
if (choiceElementList.get(k).dataFormatId == 1) {
radioButton = new RadioButton(getContext());
radioButton.setText(choiceElementList.get(k).getDataFormatValue());
radioButton.setLayoutParams(params1);
radioButton.setPadding(0, 5, 0, 5);
Log.e("setid", String.valueOf(choiceElementList.get(k).getId())) ;
radioGroup.addView(radioButton);
}
}
尝试恢复
if(choiceElementList.get(k).getId() == Cons.Id){
radioButton.setChecked(true);
}
【问题讨论】:
-
是的,正确的。我将 id 添加到 ArrayList
.
标签: java android android-studio retrofit