List within Spinner Layout

Asked

Viewed 127 times

0

Hello, I wonder if you have how to put the list that is inside Spinner directly in the layout.

Normally I do so:

 horario = new ArrayList<>();
    horario.add("");
    horario.add("Aberto Hoje");
    horario.add("Não importa");
    adapter = new ArrayAdapter<String>(getApplication(), android.R.layout.simple_spinner_dropdown_item, horario);
    spinnerhora.setAdapter(adapter);

I would like to put inside the xml. Thank you

1 answer

4


Declare in your strings.xml file

<string-array name="options">
<item>Aberto hoje</item>
<item>Não importa</item>
</string-array>

And his spinner:

<Spinner 
        android:id="@+id/spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:entries="@array/options"
    />

Source

  • Wow, thank you so much! Perfect!

  • Hi Hugo, but one thing, changed the color of the text of my spinner with this. You know how I can change the color of the text?

  • Take a look at that answer http://stackoverflow.com/questions/6159113/android-where-is-the-spinner-widgets-text-color-attribute-hiding

Browser other questions tagged

You are not signed in. Login or sign up in order to post.