Hi I’m trying to create an app for Android and in order to develop it i need to navigate through different pages and questions. For this task I have defined a radiogroup with some radiobuttons. However these radiobuttons remain the same when the user goes the next or previous question ( it only changes the text but not the selected answer, which is always the selected one for every one). For that reason i think I need to create new RadioButtons when I go to the next question but that save the state if I go to the previous question.
Here is part of my code if you could help
XML:
<RadioGroup
android:id="@+id/respuestas3RG"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_below="@id/imagenenunciado3"
android:orientation="vertical">
<RadioButton
android:id="@+id/respuesta3A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A. RespuestaA"/>
<RadioButton
android:id="@+id/respuesta3B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B. RespuestaB"/>
<RadioButton
android:id="@+id/respuesta3C"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C. RespuestaC"/>
<RadioButton
android:id="@+id/respuesta3D"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="D. RespuestaD"/>
</RadioGroup>
Java:
bNext.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
posicion = posicion +1;
questions.Next();
currentQuestion();
}
I don’t know if the best option is to create all the radioButtons at the start or generate them when the user goes through the next question.
Thank You
You don’t need to recreate it, save the state(answer) before you clear the checks with
setChecked(false);