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 :

seekbar associée à un radiogroup


Sujet :

Composants graphiques Android

  1. #1
    Membre habitué Avatar de rsuinux
    Homme Profil pro
    Infirmier Formateur pour logiciel de Dossiers de Soins Informatisés
    Inscrit en
    Août 2007
    Messages
    128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Vienne (Limousin)

    Informations professionnelles :
    Activité : Infirmier Formateur pour logiciel de Dossiers de Soins Informatisés
    Secteur : Santé

    Informations forums :
    Inscription : Août 2007
    Messages : 128
    Points : 170
    Points
    170
    Par défaut seekbar associée à un radiogroup
    Bonsoir,
    J'ai un souci avec une sekkbar, associée à un radiogroup:
    Mon radiogroup à 10 radioboutons, et ma seekbar doit aller de 0 à 10, par pas de 1. Pour info, c'est une app pour noter la douleur selon une échelle dite 'EN' (échelle numérique) de 0 à 10.
    Mon layout:
    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
    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
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    <RadioGroup
    android:id="@+id/Radio_Douleur"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="false"
    android:minHeight="0dp"
    android:minWidth="0dp"
    android:orientation="horizontal"
    android:weightSum="0">
    
        <RadioButton
    android:id="@+id/defaultSelection"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/custom_radio_button"
    android:button="@null"
    android:gravity="center"
    android:text="0"
    android:textAppearance="?android:attr/textAppearanceSmall"
    />
    
        <RadioButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/custom_radio_button"
    android:button="@null"
    android:gravity="center"
    android:text="1"
    android:textAppearance="?android:attr/textAppearanceSmall"
    />
    
        <RadioButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/custom_radio_button"
    android:button="@null"
    android:gravity="center"
    android:text="2"
    android:textAppearance="?android:attr/textAppearanceSmall"
    />
    
        <RadioButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/custom_radio_button"
    android:button="@null"
    android:gravity="center"
    android:text="3"
    android:textAppearance="?android:attr/textAppearanceSmall"
    />
    
        <RadioButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/custom_radio_button"
    android:button="@null"
    android:gravity="center"
    android:text="4"
    android:textAppearance="?android:attr/textAppearanceSmall"
    />
    
        <RadioButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/custom_radio_button"
    android:button="@null"
    android:gravity="center"
    android:text="5"
    android:textAppearance="?android:attr/textAppearanceSmall"
    />
    
        <RadioButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/custom_radio_button"
    android:button="@null"
    android:gravity="center"
    android:text="6"
    android:textAppearance="?android:attr/textAppearanceSmall"
    />
    
        <RadioButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/custom_radio_button"
    android:button="@null"
    android:gravity="center"
    android:text="7"
    android:textAppearance="?android:attr/textAppearanceSmall"
    />
    
        <RadioButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/custom_radio_button"
    android:button="@null"
    android:gravity="center"
    android:text="8"
    android:textAppearance="?android:attr/textAppearanceSmall"
    />
    
        <RadioButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/custom_radio_button"
    android:button="@null"
    android:gravity="center"
    android:text="9"
    android:textAppearance="?android:attr/textAppearanceSmall"
    />
    
        <RadioButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/custom_radio_button"
    android:button="@null"
    android:gravity="center"
    android:text="10"
    android:textAppearance="?android:attr/textAppearanceSmall"
    />
    </RadioGroup>
    
    
    <SeekBar
    android:id="@+id/Seek_Douleur"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:max="10"
    android:paddingEnd="6dip"
    android:paddingStart="6dip"
    android:progress="0"
    android:progressDrawable="@drawable/progress"
    android:thumb="@drawable/curseur"
    android:thumbOffset="10dp"/>
    Et mon code:
    (je passe les détails)
    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
    public class Nouvelle_Migraine .....
    SeekBar seekBar;
    RadioGroup rg;
    RadioButton selectedRadioButton;
    
    .../...
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
        super.onCreate (savedInstanceState);
    .../...
    rg = (RadioGroup) findViewById (R.id.Radio_Douleur);
        // on met le premier bouton à "true"
    ((RadioButton) rg.getChildAt (0)).setChecked (true);
        // On pose notre listener sur le radio group
    setRadioButton();
    
        seekBar = (SeekBar) findViewById (R.id.Seek_Douleur);
        // gestion de la seekbarr de la douleur
    seekBar.setOnSeekBarChangeListener (this);
    .../...
    }
    
    // gestion de la seekbar
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        // à partir de la on change l'état des radio bouton quand la seekbar change
    Log.d ("seekbar", "id= " + progress);
        ((RadioButton) rg.getChildAt (progress)).setChecked (true);
    }
    
    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
    
    }
    
    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
    
    }
    
    // gestion des radio boutons
    public void setRadioButton()
    {
        //Récupérer le Radio Button qui est sélectionné
    int selectedId = rg.getCheckedRadioButtonId();
        selectedRadioButton = (RadioButton) findViewById(selectedId);
    
        //Listener
    rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
                selectedRadioButton = (RadioButton) findViewById(checkedId);
                seekBar.setProgress(checkedId);
                Log.d ("radiobouton", "id= " + checkedId);
                Toast.makeText(context, String.valueOf(selectedRadioButton.getText().toString()), Toast.LENGTH_SHORT).show();
            }
        });
    }
    A présent, cela marche ... presque!
    lorsque je bouge la seekbar, je monte de 1 en 1, la c'est bon, mais dès que je vais sur 0, dans les log, j'ai ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    10-19 18:46:09.364 20489-20489/org.suinot.migraine I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
    10-19 18:46:09.462 20489-20489/org.suinot.migraine I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP
    10-19 18:46:09.464 20489-20489/org.suinot.migraine D/seekbar: id= 10
    10-19 18:46:09.465 20489-20489/org.suinot.migraine D/radiobouton: id= 10
    10-19 18:46:09.471 20489-20489/org.suinot.migraine D/radiobouton: id= 2131427479
    mon radio bouton ne va pas à 0 et ma seekbar va à 10.

    J'avoue ne pas comprendre l'id=2131427479.
    Est-ce que les radioboutons peuvent aller de 0 à 10? ou j'ai loupé quelque chose?

    Merci de votre aide.
    Rémi.
    Si tu ne sais pas: demande, si tu sais, partage.

  2. #2
    Modérateur
    Avatar de MasterMbg
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2011
    Messages
    719
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Kinshasa

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2011
    Messages : 719
    Points : 1 493
    Points
    1 493
    Par défaut
    Salut,

    Quel comportement voudrais-tu avoir exactement? Je déplace mon seekbar et du coup, un radioButton dont le texte correspond à la valeur dans le seekbar devienne sélectionné. Ou soit, je sélectionne un radioButton puis le seekbar change en fonction du texte (abusivement valeur) du radioButton.


    Christian Djo,
    Plus tu apprends sérieusement, plus tu te rapproches d'un savoir noble. Une chose est certaine, les difficultés ne s'écarteront de ton chemin...

    Tu es nouveau dans le développement Android, la page des COURS est là pour te faciliter la vie
    Tu peux trouver la réponse à ta question dans la FAQ
    Retrouvez mon tutoriel sur la consommation des services web SOAP
    Pense à voter positivement en appuyant sur en bas à droite de la réponse qui t'a donné une piste de solution.

  3. #3
    Membre habitué Avatar de rsuinux
    Homme Profil pro
    Infirmier Formateur pour logiciel de Dossiers de Soins Informatisés
    Inscrit en
    Août 2007
    Messages
    128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Vienne (Limousin)

    Informations professionnelles :
    Activité : Infirmier Formateur pour logiciel de Dossiers de Soins Informatisés
    Secteur : Santé

    Informations forums :
    Inscription : Août 2007
    Messages : 128
    Points : 170
    Points
    170
    Par défaut
    Et bien , en fait, les deux!
    l'utilisateur doit pouvoir choisir une valeur soit par choix en glissant le curseur de la seekbar (et à ce moment, l'un des radio bouton se sélectionne en fonction de la valeur) soit il choisi un radio bouton, et dans ce cas la seekbar se positionne à la même valeur.
    Cela fonctionne pour les valeurs de 1 à 10 (la seekbar ou les radioboutons) mais dès que je passe sur le bouton "0" (libellé "0" mais pas d'Id véritable, je n'ai donné un Id qu'au RadioGroup) j'ai ma sekkbar qui va à 10 (maximum) et jamais à 0
    Et je ne peux même pas la mettre à 0.
    L'Id donné par mon Log.d pour le radiobouton lorsque je déplace la seekbar à 0 est
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    D/radiobouton: id= 2131427470

    J'ai reformaté mon code, mais cela n'a rien changé.
    Si tu ne sais pas: demande, si tu sais, partage.

  4. #4
    Membre habitué Avatar de rsuinux
    Homme Profil pro
    Infirmier Formateur pour logiciel de Dossiers de Soins Informatisés
    Inscrit en
    Août 2007
    Messages
    128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Vienne (Limousin)

    Informations professionnelles :
    Activité : Infirmier Formateur pour logiciel de Dossiers de Soins Informatisés
    Secteur : Santé

    Informations forums :
    Inscription : Août 2007
    Messages : 128
    Points : 170
    Points
    170
    Par défaut
    J'ai résolu le problème, en modifiant le retour du radiobouton comme suit:
    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
        // gestion des radio boutons
    public void setRadioButton() {
            //Récupérer le Radio Button qui est sélectionné
    int selectedId = rg.getCheckedRadioButtonId ();
            final String selectedRadioButton;
    
            //Listener sur le radiogroup (=rg)
    rg.setOnCheckedChangeListener (new RadioGroup.OnCheckedChangeListener () {
                @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
                    final RadioButton rb = (RadioButton) findViewById (checkedId);
                    String r1=(String) rb.getText() ;
    
    Log.d ("radiobouton", "rb=" + r1+".");
    
                    seekBar.setProgress (Integer.decode (r1));
    }
            });
        }
    Et à présent, cela fonctionne. Le checkedId retourné est pourtant un Id, mais je n'ai pas compris pourquoi cela me faisait tout planter.
    En tout cas, c'est résolu. Problème suivant!
    Si tu ne sais pas: demande, si tu sais, partage.

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

Discussions similaires

  1. [FLASH 8] Associé SeekBar a un mp3
    Par jbidou88 dans le forum Flash
    Réponses: 8
    Dernier message: 07/06/2006, 11h35
  2. [VB6] [Install] Associer une icone à un raccourci
    Par petitgognol dans le forum Installation, Déploiement et Sécurité
    Réponses: 7
    Dernier message: 30/10/2002, 20h20
  3. [Delphi] Association composants-projet
    Par Pierre Castelain dans le forum Composants VCL
    Réponses: 6
    Dernier message: 31/07/2002, 16h20
  4. associer une base de données(access) a un dbgrid
    Par ange1708 dans le forum MFC
    Réponses: 3
    Dernier message: 11/06/2002, 12h18
  5. [Kylix] icone associée à un programme
    Par Anonymous dans le forum EDI
    Réponses: 1
    Dernier message: 22/03/2002, 09h43

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