List within the Spinner Layout

0

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

I usually do this:

 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

    
asked by anonymous 06.12.2016 / 03:36

1 answer

3

Declare in your strings.xml file

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

And your spinner:

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

Font

    
06.12.2016 / 03:52