Im trying to implement an expandable list view adapter.
I have this data that im representing in the adapter
private Map<Group, List<Contact>> groupedContactList = new HashMap<Group, List<Contact>>();
I overrode the getGroup
method fine and it works but I am having trouble overriding the getChild
method because the child is a list and im not sure if you're supposed to return the whole list or just one member in the list.
EDIT: entire class
public class MyGroupsAdapter extends BaseExpandableListAdapter {
private LayoutInflater mInflater;
private Context context;
private Map<Group, List<Contact>> groupedContactList = new HashMap<Group, List<Contact>>();
public MyGroupsAdapter(HashMap<Group, List<Contact>> groupedContactList,
Context context) {
this.groupedContactList = groupedContactList;
this.context = context;
mInflater = LayoutInflater.from(context);
}
@Override
public Contact getChild(int groupPosition, int childPosition) {
return getGroup(groupPosition+1).getContactsInGroup().get(childPosition+1);
}
@Override
public long getChildId(int arg0, int arg1) {
return arg0;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String contactRow = (String) getChild(groupPosition,
childPosition).getFullName();
mInflater = LayoutInflater.from(context);
if (convertView == null) {
convertView = mInflater.inflate(
R.layout.groups_exp_list_view_child, null);
}
TextView item = (TextView) convertView.findViewById(R.id.ListItem);
item.setText(contactRow);
return convertView;
}
@Override
public int getChildrenCount(int arg0) {
return groupedContactList.size();
}
@Override
public Group getGroup(int arg0) {
// return
// groupedContactList.get(HomeScreenActivity.groupsDB.getGroup(arg0+1));
return (Group)groupedContactList.keySet().toArray()[arg0];
//return HomeScreenActivity.groupsDB.getGroup(arg0 + 1);
}
@Override
public int getGroupCount() {
return groupedContactList.keySet().size();
}
@Override
// /PROBABLY WRONGH
public long getGroupId(int arg0) {
return arg0;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
final String groupName = getGroup(groupPosition).getName();
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(
R.layout.groups_exp_list_view_header, null);
}
TextView item = (TextView) convertView.findViewById(R.id.ListHeader);
item.setTypeface(null, Typeface.BOLD);
item.setText(groupName);
return convertView;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int arg0, int arg1) {
return true;
}
}