i\'m trying to retrieve data from a hashmap with multiple values for 1 key and set it to a listview,but instead of setting the values into the listview and displaying the listv
SimpleAdapters Consturctor states as it's second parameter:
data: A List of Maps. Each entry in the List corresponds to one row in the list. The Maps contain the data for each row, and should include all the entries specified in "from"
but HashMap<String, List<String>>
hm is a map of lists. So like List<Map<String,String>> hm
would be the datatype you probably need.
Here is the edited source:
ListView lv = (ListView)findViewById(R.id.list);
List<Map<String,String>> mapList = new ArrayList<Map<String, String>>();
Map<String,String> mapPerRow;
for (int i = 0; i < rowNumbers; i++) {
mapPerRow = new HashMap<String, String>();
mapPerRow.put("column1", value1);
mapPerRow.put("column2", value2);
mapList.add(mapPerRow);
}
ListAdapter adapter = new SimpleAdapter(
MainActivitty.this, mapList,
R.layout.list_item, new String[] { "column1", "colum2"},
new int[] { R.id.value1,R.id.value2 });
// updating listview
lv.setAdapter(adapter);
I don't get why you want the key in it (just add Strings to the map if you need more)?