0

I need to select a list from a list of spinner titles, for example If I choose Wheat in the android spinner options, it would select Wheat = [wheat, durum wheat, semolina, spelt, kamut, eincorn, faro, barley, rye, oat, malt, couscous] and output this data to the next Activity. How would I go about doing this? Thanks!

 <string-array name="restrictions">
        <item>Wheat</item>
        <item>Crustaceans</item>
        <item>Eggs</item>
        <item>Fish</item>
        <item>Peanuts</item>
        <item>Soya</item>
        <item>Milk</item>
        <item>Celery</item>
        <item>Mustard</item>
        <item>Sesame</item>
        <item>Lupin</item>
        <item>Nuts</item>
        <item>Sulphites</item>
        <item>Molluscs</item>
        <item>WADA Banned Substances</item>
    </string-array>

  <string-array name="Wheat">
        <item>wheat</item>
        <item>durum wheat</item>
        <item>semolina</item>
        <item>spelt</item>
        <item>kamut</item>
        <item>eincorn</item>
        <item>faro</item>
        <item>barley</item>
        <item>rye</item>
        <item>oat</item>
        <item>malt</item>
    </string-array>
Brad Larson
  • 170,088
  • 45
  • 397
  • 571

1 Answers1

0

To select value using spinner, use this code

Spinner spinner = (Spinner)findViewById(R.id.spinner);
String text = spinner.getSelectedItem().toString();

Then you can check the selected value

if(text.equals("Wheat"))
  { 
     List<String> list = Arrays.asList(getResources().getStringArray(R.array.Wheat));
     (list).forEach(System.out::println);
  }
John Joe
  • 12,412
  • 16
  • 70
  • 135