IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants graphiques Android Discussion :

Comment créer RadioGroup


Sujet :

Composants graphiques Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de stracoma
    Homme Profil pro
    Médecin
    Inscrit en
    Août 2013
    Messages
    413
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : Maroc

    Informations professionnelles :
    Activité : Médecin

    Informations forums :
    Inscription : Août 2013
    Messages : 413
    Par défaut Comment créer RadioGroup
    Bonjour à vous tous
    j'ai besoin de votre aide pour résoudre un problème.
    j'ai créé une application dont le graphique est le suivant:

    Nom : radioButton.jpg
Affichages : 175
Taille : 16,3 Ko

    voilà son code xml:

    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            tools:context=".MainActivity">
     
        <RadioGroup
                android:layout_width="match_parent"
                android:layout_height="match_parent"
            >
     
            <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Groupe 1"
                    android:textSize="20dp"
                    android:gravity="center_horizontal"
                    android:textStyle="bold"
                    android:textColor="#000"
            />
     
            <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
            >
                <RadioButton
                        android:id="@+id/rbt_lundi"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Lundi"
                />
                <RadioButton
                        android:id="@+id/rbt_mardi"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="mardi"
                        android:layout_marginLeft="100dp"
                />
     
            </LinearLayout>
     
            <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Groupe 2"
                    android:textSize="20dp"
                    android:gravity="center_horizontal"
                    android:textStyle="bold"
                    android:textColor="#000"
            />
     
            <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
            >
                <RadioButton
                        android:id="@+id/rbt_mercredi"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="mercredi"
                />
                <RadioButton
                        android:id="@+id/rbt_jeudi"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="jeudi"
                        android:layout_marginLeft="100dp"
                />
     
            </LinearLayout>
     
            <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Groupe 3"
                    android:textSize="20dp"
                    android:gravity="center_horizontal"
                    android:textStyle="bold"
                    android:textColor="#000"
            />
     
            <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
            >
                <RadioButton
                        android:id="@+id/rbt_vendredi"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="vendredi"
                />
                <RadioButton
                        android:id="@+id/rbt_samedi"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="samedi"
                        android:layout_marginLeft="100dp"
                />
     
            </LinearLayout>
     
        </RadioGroup>
     
    </LinearLayout>

    je ne comprends pas pourquoi malgré que mes radiobutton sont dans le même radiogroup j'ai plusieurs sélections à la fois
    Merci

  2. #2
    Membre éclairé Avatar de stracoma
    Homme Profil pro
    Médecin
    Inscrit en
    Août 2013
    Messages
    413
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : Maroc

    Informations professionnelles :
    Activité : Médecin

    Informations forums :
    Inscription : Août 2013
    Messages : 413
    Par défaut
    Bonjour
    est-ce impossible de mettre un TextView entre 2 RadiioButton d'un RadioGroup?
    merci

  3. #3
    Membre éclairé Avatar de stracoma
    Homme Profil pro
    Médecin
    Inscrit en
    Août 2013
    Messages
    413
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : Maroc

    Informations professionnelles :
    Activité : Médecin

    Informations forums :
    Inscription : Août 2013
    Messages : 413
    Par défaut
    bonsoir
    j'ai fait du bricolage!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    class MainActivity : AppCompatActivity() {
     
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
     
            val mesRadioBoutons= listOf(rbt_lundi,rbt_mardi,rbt_mercredi,rbt_jeudi,rbt_vendredi,rbt_samedi)
     
            fun choisir(rd:RadioButton){
                for (elem in mesRadioBoutons){
                    if (elem != rd) elem.isChecked=false
                }
            }
     
            rbt_lundi.setOnClickListener(){
                choisir(rbt_lundi)
            }
            rbt_mardi.setOnClickListener(){
                choisir(rbt_mardi)
            }
            rbt_mercredi.setOnClickListener(){
                choisir(rbt_mercredi)
            }
            rbt_jeudi.setOnClickListener(){
                choisir(rbt_jeudi)
            }
            rbt_vendredi.setOnClickListener(){
                choisir(rbt_vendredi)
            }
            rbt_samedi.setOnClickListener(){
                choisir(rbt_samedi)
            }
        }
    }
    ça marche mais je me demande pourquoi donner à chaque fois le nom du radiobutton à la fonction choisir. est ce possible de faire une fonction choisir qui prend automatiquement en paramètre le radiobutton sur lequel je clique
    Merci

Discussions similaires

  1. [FLASH 5] Comment créer un lien hypertexte
    Par ajit dans le forum Flash
    Réponses: 4
    Dernier message: 30/03/2006, 12h26
  2. Comment créer des barres de Menu ?
    Par MoKo dans le forum IHM
    Réponses: 5
    Dernier message: 30/07/2003, 14h58
  3. Comment créer un nouveau dossier par programmation ?
    Par annecyrond dans le forum Langage
    Réponses: 3
    Dernier message: 27/03/2003, 07h59
  4. Comment créer et executer un .EXE
    Par maher12 dans le forum Flash
    Réponses: 3
    Dernier message: 26/09/2002, 08h33
  5. [] [Stratégie] Comment créer un fichier log
    Par Skeezo dans le forum Installation, Déploiement et Sécurité
    Réponses: 4
    Dernier message: 16/09/2002, 18h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo