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 récupérer l'élément sélectionné dans un RadioGroup ?


Sujet :

Composants graphiques Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre très actif
    Homme Profil pro
    Inscrit en
    Février 2010
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 118
    Par défaut Comment récupérer l'élément sélectionné dans un RadioGroup ?
    ------------------------------------------|
    interface 1 |
    "bla bla" |
    radio1 1 radio1 2 radio3 3 radio4 4 radio5 5 |
    "ded ded" |
    radio1 1 radio1 2 radio3 3 radio4 4 radio5 5 |
    |
    bouton --------------------------------------->> action vers interface 2
    ------------------------------------------|

    |----------------------
    |interface 2
    | blabla : "valeur radioX"
    |ded ded:"valeur radioY"
    |----------------------

    en gros dans mon programme je veux que lorsque je click sur bouton je lance une nouvelle interface avec les radio sélectionner récupérer a partir de l'interface actuelle .......

    ***Merci de m’aidai pour régler le problème de récupération de la valeur*** selectinner dans lé radioGroup
    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
    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
     
     <RadioGroup
            android:id="@+id/group1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checkedButton="@+id/radio2"
            android:gravity="center"
            android:orientation="horizontal" >
     
        	<RadioButton 
        	    android:id="@+id/radio1"
        		android:layout_width="wrap_content"
        		android:layout_height="wrap_content"
        		android:text="1"
        	/>
        	<RadioButton 
        		android:id="@+id/radio2"
        		android:layout_width="wrap_content"
        		android:layout_height="wrap_content"
        		android:text="2"
        	/>
        	<RadioButton 
        		android:id="@+id/radio3"
        		android:layout_width="wrap_content"
        		android:layout_height="wrap_content"
        		android:text="3"
        	/>
        	<RadioButton 
        		android:id="@+id/radio4"
        		android:layout_width="wrap_content"
        		android:layout_height="wrap_content"
        		android:text="4"
        	/>
        	<RadioButton 
        		android:id="@+id/radio5"
        		android:layout_width="wrap_content"
        		android:layout_height="wrap_content"
        		android:text="5"
        	/>
        </RadioGroup>
    -------------------------------
     <RadioGroup
            android:id="@+id/group2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checkedButton="@+id/radio2"
            android:gravity="center"
            android:orientation="horizontal" >
     
        	<RadioButton 
        	    android:id="@+id/radio1"
        		android:layout_width="wrap_content"
        		android:layout_height="wrap_content"
        		android:text="1"
        	/>
        	<RadioButton 
        		android:id="@+id/radio2"
        		android:layout_width="wrap_content"
        		android:layout_height="wrap_content"
        		android:text="2"
        	/>
        	<RadioButton 
        		android:id="@+id/radio3"
        		android:layout_width="wrap_content"
        		android:layout_height="wrap_content"
        		android:text="3"
        	/>
        	<RadioButton 
        		android:id="@+id/radio4"
        		android:layout_width="wrap_content"
        		android:layout_height="wrap_content"
        		android:text="4"
        	/>
        	<RadioButton 
        		android:id="@+id/radio5"
        		android:layout_width="wrap_content"
        		android:layout_height="wrap_content"
        		android:text="5"
        	/>
        </RadioGroup>



    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
     
    public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
            setContentView(R.layout.note_ue_create); 
            group1 = (RadioGroup)findViewById(R.id.group1);
            group2 = (RadioGroup)findViewById(R.id.group2);
            Button bouton3 = (Button) findViewById(R.id.button3);
            bouton3.setOnClickListener((android.view.View.OnClickListener) BoutonListener); 
    }
            group1 = (RadioGroup)findViewById(R.id.group1);
            group2 = (RadioGroup)findViewById(R.id.group2);
     
    		public void onClick(android.view.View v) {
    			// TODO Auto-generated method stub
     
    			int s1 = group1.getCheckedRadioButtonId();
    			String s2= group2.getCheckedRadioButtonId(); }

  2. #2
    Membre très actif
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    406
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 406
    Par défaut
    Pour récupérer tes valeurs dans la première "activity" :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    group1= (RadioGroup) findViewById(R.id.group1);
    RadioButton group1_checked = (RadioButton) group1.getCheckedRadioButtonId();
    String val1 = group1_checked.getText().toString();
     
     
    group2= (RadioGroup) findViewById(R.id.group2);
    RadioButton group2_checked = (RadioButton) group2.getCheckedRadioButtonId();
    String val2 = group2_checked.getText().toString();
    Ensuite, dans la même activity, tu les stockes (au click je suppose) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    Intent i = new Intent(getApplicationContext(), DeuxiemeEcran.class);
    i.putExtra("val1", val1);
    i.putExtra("val2", val2);
    startActivity(i);
    Enfin, du côté de la deuxième activity, tu récupères tes valeurs comme ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    Bundle extras = getIntent().getExtras(); 
    if(extras !=null) {
        String val1 = extras.getString(val1);
        String val2 = extras.getString(val2);
    }
    Source : http://remwebdevelopment.com/dev/a33...ctivities.html

  3. #3
    Membre très actif
    Homme Profil pro
    Inscrit en
    Février 2010
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 118
    Par défaut
    merci zakaria,
    mais c'est pas tous a fait la solution parce que :
    il m'affiche cette erreur :
    Cannot cast from int to RadioButton
    on peut faire ceci :
    RadioButton group1_checked = (RadioButton) group1.getCheckedRadioButtonId();

  4. #4
    Membre très actif
    Homme Profil pro
    Inscrit en
    Février 2010
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 118
    Par défaut
    solution :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    final RadioButton radio_red = (RadioButton)findViewById(group9.getCheckedRadioButtonId());
                String r1=(String) radio_red.getText() ;

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 07/03/2008, 08h49
  2. Comment récupérer le texte sélectionné dans une liste déroulante ?
    Par Je-cherche-pfe dans le forum Windows Forms
    Réponses: 3
    Dernier message: 02/09/2007, 20h35
  3. Récupérer l'élément sélectionné dans un GtkTree
    Par slasher-fun dans le forum GTK+ avec C & C++
    Réponses: 1
    Dernier message: 07/03/2007, 17h33
  4. Réponses: 1
    Dernier message: 18/05/2006, 11h37
  5. Réponses: 3
    Dernier message: 13/12/2005, 00h21

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