Good morning, I'm starting to work with expandable lists but I run into the following problem:
1. I have the following expandable list
When clicking on one of the questions, this question is displayed with a spinner to select the correct answer
The problem is that when you instantiate all the questions from the same .xml object When selecting an option of the spinner, the same option is selected in the other spinner of each question, I would like to know how I can make these elements independent.
xml question
<TextView
android:id="@+id/txtPreguntaEst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="TextView"
android:textSize="18sp"
android:textStyle="bold|italic"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="16dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="16dp" />
<TextView
android:id="@+id/txtRespuesta1Est"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="TextView"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="79dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="16dp" />
<TextView
android:id="@+id/txtRespuesta2Est"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="TextView"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="26dp"
app:layout_constraintTop_toBottomOf="@+id/txtRespuesta1Est"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp" />
<TextView
android:id="@+id/txtRespuesta4Est"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="TextView"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="25dp"
app:layout_constraintTop_toBottomOf="@+id/txtRespuesta3Est"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp" />
<TextView
android:id="@+id/txtRespuesta3Est"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="TextView"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="23dp"
app:layout_constraintTop_toBottomOf="@+id/txtRespuesta2Est"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp" />
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="2dp"
android:background="@color/blueShine"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="@+id/textView16"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="33dp"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="33dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@+id/txtRespuesta4Est" />
<Spinner
android:id="@+id/spnComun"
android:layout_width="100dp"
android:layout_height="0dp"
android:layout_marginStart="6dp"
android:entries="@array/opcionesRespuestas"
tools:layout_constraintTop_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/textView16"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="6dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="6dp" />
<TextView
android:id="@+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Slecciona la respuesta correcta"
tools:layout_constraintTop_creator="1"
tools:layout_constraintBottom_creator="1"
android:layout_marginStart="5dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="51dp"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="46dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@+id/txtRespuesta4Est"
android:layout_marginLeft="5dp" />
This is the event when you display the list
@Override
public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
final String cadenaPregunta = (String)getChild(i,i1);
if(view == null)
{
LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.activity_presentacion_pruebas,null);
}
String [] pregunta = cadenaPregunta.split(",");
txtPregunta = (TextView) view.findViewById(R.id.txtPreguntaEst);
txtPregunta.setText(pregunta[1]);
txtRespuesta1 = (TextView) view.findViewById(R.id.txtRespuesta1Est);
txtRespuesta1.setText(pregunta[2]);
txtRespuesta2 = (TextView) view.findViewById(R.id.txtRespuesta2Est);
txtRespuesta2.setText(pregunta[3]);
txtRespuesta3 = (TextView) view.findViewById(R.id.txtRespuesta3Est);
txtRespuesta3.setText(pregunta[4]);
txtRespuesta4 = (TextView) view.findViewById(R.id.txtRespuesta4Est);
txtRespuesta4.setText(pregunta[5]);
return view;
}
I hope it was clear, thank you very much