Ich habe einen Radioknopf in Radiogroup erstellt, aber wenn ich versuche, die Apps auszuführen, können alle Radioknöpfe ständig ausgewählt werden, und wie man nur einen setzt Radiobutton kann gleichzeitig ausgewählt werden?Wie man nur einen RadioButton einstellt Kann zu der Zeit in RadioGroup ausgewählt werden
Ich verwende Fragment
RadioGroup radioGroup = (RadioGroup) rootView.findViewById(R.id.RGroup);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// find which radio button is selected
if(checkedId == R.id.Abdominal) {
Toast.makeText(getActivity().getApplicationContext(), "choice: A",
Toast.LENGTH_SHORT).show();
} else if(checkedId == R.id.Arm) {
Toast.makeText(getActivity().getApplicationContext(), "choice: B",
Toast.LENGTH_SHORT).show();
} else if(checkedId == R.id.Back){
Toast.makeText(getActivity().getApplicationContext(), "choice: C",
Toast.LENGTH_SHORT).show();
} else if(checkedId == R.id.Chest){
Toast.makeText(getActivity().getApplicationContext(), "choice: D",
Toast.LENGTH_SHORT).show();
} else if(checkedId == R.id.Leg){
Toast.makeText(getActivity().getApplicationContext(), "choice: E",
Toast.LENGTH_SHORT).show();
} else if(checkedId == R.id.Shoulder){
Toast.makeText(getActivity().getApplicationContext(), "choice: F",
Toast.LENGTH_SHORT).show();
}
}
});
hier mein xml-Code für RG und RB
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/RGroup">
<TableRow android:weightSum="1">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Abdominal"
android:id="@+id/Abdominal"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Arm"
android:id="@+id/Arm"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:id="@+id/Back" />
</TableRow>
<TableRow>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chest"
android:id="@+id/Chest"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Leg"
android:id="@+id/Leg"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Shoulder"
android:id="@+id/Shoulder"/>
</TableRow>
</RadioGroup>
Edited 1: Antwort: Wenn Sie nicht wollen, Radio-Button ausgewählt werden in einer Zeit, so verwenden Sie nicht Charerow
, Wow Dank! Dies ist die Antwort, alle Taste kann einmal bc von tablerow ausgewählt werden :) Danke für Hilfe –
Btw, ich benutze TableRow, um einen Radiobutton in 2 Zeilen zu machen, so wie es 2rwos ohne tablerow machen? –
lass mich sehen .. ich werde das bald aktualisieren .. !! –