【发布时间】:2016-10-05 21:34:16
【问题描述】:
我有一个无线电组,它根据前一组问题的答案加载问题。是同一个电台组,只是问题变了。
这是我加载问题的代码部分;
if (key.substring(0,2).equalsIgnoreCase("CS")){
actionText.setVisibility(View.GONE);
radioGroup.setVisibility(View.VISIBLE);
radioGroup.removeAllViews();
btnForward.setEnabled(true);
Set optTextset=thisScreenOpts.lhmOptionText.entrySet();
Set optAnswerSet=thisScreenOpts.lhmNextStep.entrySet();
Iterator i=optTextset.iterator();
Iterator i2=optAnswerSet.iterator();
if (thisScreenOpts.title!=null){
myText.setText(thisScreenOpts.title);
}else{
myText.setText("");
}
while (i.hasNext()){
Map.Entry optTextMap=(Map.Entry)i.next();
Map.Entry optAnswerMap=(Map.Entry)i2.next();
RadioButton radioButton=new RadioButton(this);
radioButton.setTag(optAnswerMap.getValue().toString());
radioButton.setText(optTextMap.getValue().toString());
radioGroup.addView(radioButton);
}
}
我有一个前进按钮,用于检查单击了哪个单选按钮;
if (masterkey.substring(0,2).equalsIgnoreCase("CS")) {
if (radioGroup.getCheckedRadioButtonId() == -1) {
Toast.makeText(getBaseContext(), "Please select an option", Toast.LENGTH_SHORT).show();
break;
}
int selectedID = radioGroup.getCheckedRadioButtonId();
RadioButton selectedRadio = (RadioButton) findViewById(selectedID);
keyTag = selectedRadio.getTag().toString();
backList.add(masterkey);
masterkey = keyTag;
createScreen(masterkey);
break;
}
我的问题是选择的索引,或者结果;
radioGroup.getCheckedRadioButtonId()
即使我删除视图也不会被清除。所以keyTag = selectedRadio.getTag().toString(); 给出了一个 nullPointerException。
请告诉我如何重置无线电组的选定索引。
提前致谢
【问题讨论】:
标签: android android-radiogroup