i want to implement expandable list view with multiple child layouts. all works fine but problem om,child view..child not appear on appropriate position.... here is my code...PL
BaseExpandableListAdapter
doesn't have getViewTypeCount()
and getItemViewType(). in order to have different children view types you have to override the following methods instead.
@Override
public int getChildTypeCount() {
return 2;
}
@Override
public int getChildType(int groupPosition, int childPosition) {
if (getChildId(groupposition, childposition)==3)
return 0;
//Not free
else
return 1;
}
I have done this by add and remove the header view under the parent group layout.
If you group layout is a LinearLayout
that have orientation="vertical"
like this
<LinearLayout
android:id="@+id/group_layout_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
I add a references to the ExpandableListView
in my constructor for my ExpandListAdapter
so I can check if the group is expanded
private ExpandableListView list;
public ExpandListAdapter(Context context, ArrayList<Group> groups, ExpandableListView list) {
this.list = list;
}
and then in top of the method getGroupView
check if it is expandet and add or if it is not remove
public View getGroupView(int groupPosition, boolean isLastChild, View view, ViewGroup parent) {
final Group group = getGroup(groupPosition);
LayoutInflater inf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inf.inflate(R.layout.group_list_row, null);
final View childheader = inf.inflate(R.layout.child_list_header, null);
LinearLayout groupLayout = (LinearLayout) view.findViewById(R.id.group_layout_id);
if(list.isGroupExpanded(groupPosition)){
groupLayout.addView(childheader, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
}else{
groupLayout.removeView(childheader);
}