Ich habe eine MCQs App mit vier Radio-Buttons in einer Radio-Gruppe erstellt. Problem ist, dass ich einen Radioknopf auswählen und andere drei Radioknopfauswahl zu dieser Zeit deaktivieren möchte. Nur eine Optionsschaltfläche aktiviert und deaktiviert die Auswahl anderer Optionsfelder. Bitte helfen Sie mir aus: Ich werde Ihnen allen sehr dankbar sein.Kann nicht mit Radio-Tasten-Auswahl umgehen
----------
Xml File
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/radioGroup1">
//These are four radio buttons from which i have to select one radio button and selection of other three radio buttons must be disabled.
<RadioButton
android:id="@+id/choice1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:background="@android:color/darker_gray"
android:gravity="left|center_vertical"
android:onClick="onClick"
android:padding="4dp"
android:text="A"
android:textColor="#000000"
android:textSize="16dp" />
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="B"
android:onClick="onClick"
android:background="@android:color/darker_gray"
android:textColor="#000000"
android:padding="4dp"
android:textSize="16dp"
android:gravity="left|center_vertical"
android:layout_marginBottom="5dp"
android:id="@+id/choice2"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="C"
android:onClick="onClick"
android:background="@android:color/darker_gray"
android:textColor="#000000"
android:padding="4dp"
android:textSize="16dp"
android:gravity="left|center_vertical"
android:layout_marginBottom="5dp"
android:id="@+id/choice3"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="D"
android:onClick="onClick"
android:background="@android:color/darker_gray"
android:textColor="#000000"
android:padding="4dp"
android:textSize="16dp"
android:gravity="left|center_vertical"
android:layout_marginBottom="5dp"
android:id="@+id/choice4" />
</RadioGroup>
----------
Java File:
mQuestionView = (TextView) findViewById(R.id.question);
mButtonChoice1 = (RadioButton) findViewById(R.id.choice1);
mButtonChoice2 = (RadioButton) findViewById(R.id.choice2);
mButtonChoice3 = (RadioButton) findViewById(R.id.choice3);
mButtonChoice4 = (RadioButton) findViewById(R.id.choice4);
}
//Java file with only onclick button code:
public void onClick(View view) {
Button answer = (Button) view;
// Is the button now checked?
//here must be the code of my problem
}
was habe ich hier? if (checkedId == R.id.radio0) Radio0 ist nicht in meinem Code? –
radio0 ist Ihre Wahl1; Ich hatte den Code geändert. überprüfen Sie es einfach –
Ich muss diesen Code mit allen vier Möglichkeiten, choice1, choice2, choice3 und choice4 getrennt machen? –