Populando Spinner

Asked

Viewed 79 times

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 Restaurant 2

Within my Activity I placed two Spinners one that will pick up the Array List Restaurants and the other one I want the Array list data to appear when I select the restaurant and at the end I would pick up and Setaria as a Price Text View.

Follow the image to get a better sense

inserir a descrição da imagem aqui

Just to get an idea of what’s being populated in the Spinners

<string-array name="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>

1 answer

1

You can be populating according to the spinner dishes according to the selection of the restaurants spinner 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
             }
        }

Browser other questions tagged

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