0

I have a HashMap which contains a key and value, both of which are strings. I am getting the HashMap from a different activity. I am trying to use the HashMap and put it into an array adapter so I can display a spinner with the values of the HashMap. I have tried to iterate through the HashMap and haven't had any luck.

HashMap<String, String> examCodesMap = (HashMap<String, String>) MainActivity.examCodesMap;
HudZah
  • 55
  • 1
  • 8

1 Answers1

1
HashMap<String, String> examCodesMap = new HashMap<String, String>();
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayList<String> arrayList = new ArrayList<>();

for(Map.Entry<String, HashMap> entry : selects.entrySet()) {
    String key = entry.getKey();
    String value = entry.getValue();

    arrayList.add(value);
}

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.spinner, arrayList);
BWappsAndmore
  • 491
  • 3
  • 17
  • What is selects.entrySet() – HudZah Jan 23 '20 at 01:49
  • **HashMap entrySet() Method in Java** The java.util.HashMap.entrySet() method in Java is used to create a set out of the same elements contained in the hash map. It basically returns a set view of the hash map or we can create a new set and store the map elements into them. further reading [here](https://www.geeksforgeeks.org/hashmap-entryset-method-in-java/) – BWappsAndmore Jan 23 '20 at 07:57