我正在开展测验申请。我在每个页面中显示问题及其选项(单选按钮),其中包含下一个按钮。即,当单击下一个按钮时,将显示下一个带有其选项的问题。现在我也保留了以前的按钮。但是我遇到了后退按钮的问题,例如我在第一个问题中选择了第3个选项并且去了第2个问题并且再次点击了前一个按钮并且回到了第一个问题。在第一个问题中,所选值已消失。如何存储所选的单选按钮值以及如何在按下或按下按钮时再次选中单选按钮= true。我正在努力解决这个问题。请帮助我。
我将选中的单选按钮值存储在整数变量中。
Code:
int selectedop1 = 0;
public void nextquestion() {
if (in < parts.length - 1) {
in++;
radiogroup.clearCheck();
optionslayout.removeView(radiogroup);
for (int a = 0; a < next2.length; a++) {
next3 = next2[a].trim().split("getchoce");
stringList5.add(next3[0]);
stringList6.add(next3[1]);
stringList7.add(next3[2]);
stringList8.add(next3[3]);
}
optionslayout = (LinearLayout) findViewById(R.id.chklnlayout);
tv.setText(Html.fromHtml(next4[1].replace("\\n", "<br>")));
tv.setTextColor(Color.parseColor("#000000"));
radiogroup = (RadioGroup) new RadioGroup(Test.this);
optionslayout.addView(radiogroup);
for (int p = 0; p < next2.length; p++) {
RadioButton newRadioButton = new RadioButton(Test.this);
newRadioButton.setText(stringList6.get(p));
newRadioButton.setTextColor(Color.parseColor("#000000"));
newRadioButton.setTextSize(15);
radbtn = Integer.parseInt(stringList5.get(p));
newRadioButton.setId(radbtn);
radiogroup.addView(newRadioButton);
}
radiogroup
.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup radioGroup,
int checkedId) {
for (int h = 0; h < radioGroup.getChildCount(); h++) {
RadioButton btn = (RadioButton) radioGroup
.getChildAt(h);
if (btn.getId() == checkedId) {
selectedop1 = btn.getId();
return;
}
}
}
});
}
else
{
System.out.println("Test completed");
}
}
Previous click:
public void previouscall(View v) {
in--;
if(in >1)
{
prevquestion();
}
}
public void prevquestion() {
if (in < parts.length - 1) {
radiogroup.clearCheck();
optionslayout.removeView(radiogroup);
next1 = parts[in].trim().split("getquopim");
next4 = next1[0].trim().split("getquessplit");
next2 = next1[1].trim().split("getidoptn");
optionslayout = (LinearLayout) findViewById(R.id.chklnlayout);
tv.setText(Html.fromHtml(next4[1].replace("\\n", "<br>")));
tv.setTextColor(Color.parseColor("#000000"));
radiogroup = (RadioGroup) new RadioGroup(Test.this);
optionslayout.addView(radiogroup);
for (int p = 0; p < next2.length; p++) {
RadioButton newRadioButton = new RadioButton(Test.this);
newRadioButton.setText(stringList6.get(p));
newRadioButton.setTextColor(Color.parseColor("#000000"));
newRadioButton.setTextSize(15);
radbtn = Integer.parseInt(stringList5.get(p));
newRadioButton.setId(radbtn);
radiogroup.addView(newRadioButton);
}
radiogroup
.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup radioGroup,
int checkedId) {
for (int h = 0; h < radioGroup.getChildCount(); h++) {
RadioButton btn = (RadioButton) radioGroup
.getChildAt(h);
if (btn.getId() == checkedId) {
selectedop1 = btn.getId();
return;
}
}
}
});
}
else
{
System.out.println("test completed");
}
}