有什麼辦法來填充從ListView和地圖與值列表
Map<Integer, List<Object>>
的Android的ListView?
我願做這樣的事情:
-Key1
-Value11
-Value12
-Value13
-Key2
-Value21
-Value22
-Value23
我已經試過:
添加適配器列表視圖:
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();
}
}
我認爲主要問題map.size()返回鍵的數量在這張地圖中的值映射。
我的錯誤:通過使用ExpandableListView
FATAL EXCEPTION: main
java.lang.IndexOutOfBoundsException: Invalid index 3, size is 3
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
at java.util.ArrayList.get(ArrayList.java:304)
**
你會得到什麼錯誤? – 2014-09-20 11:45:27
IndexOutOfBoundsException。 – Shunt 2014-09-20 11:48:45