-3

I want to implement one spinner where data will come from strings.xml file and when I click on update button then the hidden key will save on server. Below is my code where I am sending integer value but I need to send:
{(Select,""),(None,"none"),(Learing Impaired,"Learing_Impaired"),etc}

How can we do this in my app?

final List<String> list2 = Arrays.asList(getResources().getStringArray(R.array.scases));
final List<KeyPairBoolData> listArray2 = new ArrayList<>();
for (int j = 0; j < list2.size(); j++) {
    KeyPairBoolData h1 = new KeyPairBoolData();
    h1.setId(j + 1);
    h1.setName(list2.get(j));
    h1.setSelected(false);
    listArray2.add(h1);

    specialCaseSpinner.setItems(listArray2, -1, new SpinnerListener() {
        @Override
        public void onItemsSelected(List<KeyPairBoolData> items) {
           for (int j = 0; j < items.size(); j++) {
               if (items.get(j).isSelected()) {
                  //  Log.i(getTag(), i + " : " + items.get(i).getName() + " : " + items.get(i).isSelected());
                  Log.e("spinner.........",items.get(j).getName() + " : " + items.get(j).isSelected());
               }
           }
        }
    });
}

Below is the string array name

 <string-array name="scases">
    <item>Select</item>
    <item>none</item>
    <item>Learing Impaired</item>
    <item>Speach impaired</item>
    <item>Dyslexic</item>
    <item>blind</item>
    <item>Polio affilicted</item>
    <item>visually challenged</item>
    <item>others</item>
</string-array>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Paramjeet Singh
  • 145
  • 1
  • 3
  • 15

1 Answers1

0

Finally I have done this, In my code, Occupation is a string array where I have defined the hidden value which will store on server but not show on spinner items and then set the id of occupation h.setId(Occupation[i]);

 String[] Occupation = {"rest_all", "Government", "Officer", "Merchant", "Shipping", "Professor", "Teacher", "Doctor",
            "Dentist", "Chartered Accountant", "Cost Accountant", "Engineer", "Software", "Educationist", "Business",
            "Civil Services", "Management"};
    final List<String> list4 = Arrays.asList(getResources().getStringArray(R.array.Occupation));
    final List<KeyPairBoolData> listArray4 = new ArrayList<>();
    for (int i = 0; i < list4.size(); i++) {
        KeyPairBoolData h = new KeyPairBoolData();
        h.setId(Occupation[i]);
        h.setName(list4.get(i));
        h.setSelected(false);
        listArray4.add(h);

        occupationSpinner.setItems(listArray4, -1, new SpinnerListener() {
            @Override
            public void onItemsSelected(List<KeyPairBoolData> items) {
                for (int i = 0; i < items.size(); i++) {
                    if (items.get(i).isSelected()) {
                        //     Log.i(getTag(), i + " : " + items.get(i).getName() + " : " + items.get(i).isSelected());
                        Log.e("spinner.........", items.get(i).getId() + " : " + items.get(i).isSelected());
                    }
                }
            }
        });
    }
Paramjeet Singh
  • 145
  • 1
  • 3
  • 15