-1
votes

Je ne veux que l'un des boutons radio à sélectionner, c'est-à-dire que la sélection multiple ne devrait pas être autorisée.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <LinearLayout
            android:id="@+id/public_line"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
        <TextView
            android:id="@+id/Public"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="6"
            android:text="Public"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="24dp"
            android:textSize="20dp"
            android:textColor="@android:color/black"/>
        <RadioButton
            android:id="@+id/public_button"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="16dp"
            android:layout_marginTop="24dp"
            />

        </LinearLayout>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginBottom="8dp"
            android:text="league is visible to the public,
                          that is, anyone can join your league"
            />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:id="@+id/Private"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="6"
                android:text="Private"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="24dp"
                android:textSize="20dp"
                android:textColor="@android:color/black"/>
            <RadioButton
                android:id="@+id/private_button"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginRight="16dp"
                android:layout_marginTop="24dp"
                />

        </LinearLayout>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginBottom="8dp"
            android:text="Only people with invite code can join"
            />
    </RadioGroup>
    <TextView
        android:layout_alignParentBottom="true"
        android:background="@drawable/orange_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Done"
        android:padding="16dp"
        android:textSize="20dp"
        android:textColor="@android:color/black"
        android:layout_weight="1"
        android:gravity="center"/>
</RelativeLayout>
Here is my layout. It allows both the radio buttons to be selected. Can someone help me figure out what the problem is? From what I know the problem is that the radio buttons are not directly in the radio group, but how am I supposed to accommodate them in the radio group directly to get this same layout. Else is there an alternate way to solve the problem

3 commentaires

Cela semble dupliquer. Consultez cette page Stackoverflow.com/a/18179176/4295522


@Acuthgovind Vous voulez dire de dire tout en conservant le même design?


Vous voudrez peut-être écrire une logique personnalisée dans ce cas.


4 Réponses :


0
votes

Le radiobutton s doit être des enfants directs de radiogroupe pour le faire gérer automatiquement la sélection unique.
De votre présentation, il semble que vous essayez d'afficher du texte sur le côté de votre radiobutton s. Pour ce faire, vous pouvez simplement définir l'attribut android: texte sur le radiobutton , pas besoin d'utiliser supplémentaire textview s.


0 commentaires

2
votes

Vos radiobuttons doivent être un enfant de radiogroupe exaclly comme celui-ci xxx

mais dans votre cas est enfant de linearlayout et chaque bouton radio peut être sélectionné


0 commentaires

0
votes

Essayez simplement celui-ci xxx


0 commentaires

0
votes

Il existe deux façons d'atteindre vos solutions

Tout d'abord est que les radiobuttons définissent directement les enfants de radiogroupe comme ci-dessous P>

 publicButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    publicButton.setChecked(true);
                    privateButton.setChecked(false);
                }
            }
        });
privateButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if(isChecked){
                            publicButton.setChecked(false);
                            privateButton.setChecked(true);
                    }
                }
            });


0 commentaires