Aller au contenu
View in the app

A better way to browse. Learn more.

Forum de Frandroid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Résolu] Spinner et Selection

Featured Replies

Posté(e)

array.xml

<?xml version="1.0" encoding="utf-8"?>


EUR
USD

Mon Spinner se trouve comme ceci dans mon layout

                                    android:id="@+id/acc_curr"
                   android:drawSelectorOnTop="true"
                   android:prompt="@string/acc_curr"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
               />

J'y ajoute les éléments de mon array.xml pour avoir une liste déroulante

Spinner s = (Spinner) findViewById(R.id.acc_curr);
       ArrayAdapter adapter = ArrayAdapter.createFromResource(
               this, R.array.acc_curr_list, android.R.layout.simple_spinner_item);
       adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
       s.setAdapter(adapter);

Je récupére la valeur de mon Spinner sous forme d'une String pour l'enregistrer dans ma base

Spinner AccCurr = (Spinner) findViewById(R.id.acc_curr);
String sAccCurr = AccCurr.getSelectedItem().toString();

Maintenant je récupére la valeur dans ma DB mais je ne sais pas comment faire pour que mon Spinner selectionne l'item qui correspond à la valeur que j'ai récupéré dans ma DB

MonSpinner.setSelection(POSITION)

Je ne peux utiliser que la position (INT) mais moi j'ai la valeur (STRING)

Comment faire ?

Modifié par Roromix

  • 2 weeks later...
Posté(e)
  • Auteur

J'ai trouvé la solution :

            for (int i = 0; i < s.getCount(); i++) {
               String value = s.getItemAtPosition(i).toString();
               if (value.equals(LAVALEURASELECTIONNER)) {
                   s.setSelection(i);
               }
           }

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

Account

Navigation

Rechercher

Rechercher

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.