Populating Spinner

1

I have the following doubt I have to use some Arrays List in my project they are ...

List Restaurant Dishes Restaurant 1 Dishes Restaurant 2 Price Restaurant 1 Price 2 Restaurant

Within my Activity I put two Spinners one that will get the Array List Restaurants and the other the I want to appear the data of the Array list when I select the restaurant and in the end I would pick up and setaria as a Text View of the price .

Follow the image to get a better idea

Justtogetanideaofwhat'sbeingpopulatedinSpinner

<string-arrayname="Restaurantes">
    <item>McDonalds</item>
    <item>KFC</item>
</string-array>

<string-array name="Restaurante_McDonalds_Pratos">
    <item>Combo Big Mac</item>
    <item>Combo Deluxe Bacon</item>
    <item>Combo Club House</item>
</string-array>

<string-array name="Restaurante_McDonalds_Pratos_Precos">
    <item>R$ 31,00</item>
    <item>R$ 29,00</item>
    <item>R$ 35,00</item>
</string-array>

<string-array name="Restaurante_KFC_Pratos">
    <item>Combo Balde de 6 peças</item>
    <item>Combo Balde de 9 peças</item>
    <item>Combo Balde de 12 peças</item>
</string-array>

<string-array name="Restaurante_KFC_Pratos_Precos">
    <item>R$ 25,00</item>
    <item>R$ 35,00</item>
    <item>R$ 45,00</item>
</string-array>
    
asked by anonymous 29.09.2017 / 15:28

1 answer

1

You can populate according to the spinner dishes according to the restaurant spinner selection through the setOnItemSelectedListener.

spnRestaurante.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            String selected = adapterView.getItemAtPosition(i).toString();
            restaurante.setRestaurante(selected);

            if(selected.equals("McDonalds")){
               //seta o adapter dos pratos para o spinner dos pratos
             } if(selected.equals("KFC")){
               //seta o adapter dos pratos para o spinner dos pratos
             }
        }
    
01.10.2017 / 16:11