Android : ListView and Map with values as List

on Saturday, September 20, 2014


Is there any way to populate android ListView from



Map<Integer, List<Object>>


?


I would like to do something like this:


-Key1


-Value11


-Value12


-Value13


-Key2


-Value21


-Value22


-Value23


I've tried:


Adding adapter to listview:



ListAdapter adapterList = new StudiesAdatper(FullWeek.this, studiesMap);
((ListView) findViewById(R.id.weekListView)).setAdapter(adapterList);


StudiesAdapter:



private class StudiesAdatper extends BaseAdapter {

private Map<Integer, List<Study>> map;
private Context context;
private int day = 0;

public StudiesAdatper(Context context, Map<Integer, List<Study>> map) {
this.context = context;
this.map = map;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(
R.layout.day_row, null);
}


if (map.get(day) == null) {
day++;
return convertView;
}

Study study = map.get(day++).get(position);
/*
* Working with study here
*/
return convertView;

}

@Override
public int getCount() {
return map.size();
}
}


I think the main problem is that map.size() returns the number of key-value mappings in this map.


0 comments:

Post a Comment