Разные дочерние макеты для разных групп ExpandableListView
У меня были проблемы, пытаясь сделать это. Я не могу понять это правильно, я хочу контролировать каждого родителя + детей этого родителя. ExpandableListView вызывает у меня головную боль. пакет комментариев;
public class CommentsExpandableListAdapter extends BaseExpandableListAdapter {
private Activity context;
private Map<String, List<String>> comments_feed_collection;
private List<String> group_list;
private boolean a_comment = false;
public CommentsExpandableListAdapter(Activity context, List<String> group_list,
Map<String, List<String>> comments_feed_collection) {
this.context = context;
this.comments_feed_collection = comments_feed_collection;
this.group_list = group_list;
}
public Object getChild(int groupPosition, int childPosition) {
return comments_feed_collection.get(group_list.get(groupPosition)).get(childPosition);
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String incoming_text = (String) getChild(groupPosition, childPosition);
LayoutInflater inflater = context.getLayoutInflater();
if (convertView == null) {
//first view
if(childPosition==0 && groupPosition==0) {
convertView = inflater.inflate(R.layout.description_of_ads_expandable_list, null);
TextView description_child = (TextView) convertView.findViewById(R.id.description_of_ads_expandable_list_child_text_view);
description_child.setText(incoming_text);
}else if(childPosition==0 && groupPosition==1){
//second view view
convertView = inflater.inflate(R.layout.comments_create_comment, null);
}else if(childPosition>=1 && groupPosition>=1){
//thrid view
convertView = inflater.inflate(R.layout.comments_expandable_list_child, null);
}
}
return convertView;
}
public int getChildrenCount(int groupPosition) {
return comments_feed_collection.get(group_list.get(groupPosition)).size();
}
public Object getGroup(int groupPosition) {
return group_list.get(groupPosition);
}
public int getGroupCount() {
return group_list.size();
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String incoming_text = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.expandable_list_single_item,
null);
}
TextView item = (TextView) convertView.findViewById(R.id.expandable_list_single_item_text_view_group);
item.setTypeface(null, Typeface.BOLD);
item.setText(incoming_text);
return convertView;
}
public boolean hasStableIds() {
return true;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
@Override
public int getChildTypeCount() {
return 3;
}
@Override
public int getGroupType(int groupPosition) {
return super.getGroupType(groupPosition);
}
@Override
public int getGroupTypeCount() {
return 3;
}
}