I have expandable list view in my application. Data is stored in this way:
ArrayList<Map<String, String>> groupData;
ArrayList<Map<String, String>> childDataItem;
ArrayList<ArrayList<Map<String, String>>> childData;
Map<String, String> m;
When i use method getChild()
:
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this.childData.get(groupData.get(groupPosition)).get(childPosititon);
}
It makes error in groupData.get(groupPosition))
How to solve it?
You are misunderstanding something - arraylist works with integer position key
so -> groupData.get(groupPosition)
returns String then you can't do childData.get(groupData.get(groupPosition))
Also you should consider a list like that =>
HashMap<String,<Map<String, String>> values;
here you have parent/child with only one list.
HashMap<String,<Map<String, String>> values;
with that :
@Override
public Object getChild(int groupPosition, int childPosititon) {
String key = values.keyset().get(groupPosition); //Father key look how words hashmap on oracle site;
parentElement = values.get(key);
childKey = parentElement.keyset().get(childPosititon);
return parentElement.get(childKey)
}
I have not factorized code to let you understand how it works. Take a look as i said, at how workds list/Map/Set. It is really important and will help you to do a cleaner code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.