Skip to content Skip to sidebar Skip to footer

Android Expandable Listview Customization On Child View

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...PLZ H

Solution 1:

BaseExpandableListAdapter doesn't have getViewTypeCount() and getItemViewType(). in order to have different children view types you have to override the following methods instead.

@OverridepublicintgetChildTypeCount() {
    return2;
}

@OverridepublicintgetChildType(int groupPosition, int childPosition) {
if (getChildId(groupposition, childposition)==3) 
        return0;

    //Not freeelsereturn1;
}

Solution 2:

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;

    publicExpandListAdapter(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) {
    finalGroupgroup= getGroup(groupPosition);

    LayoutInflaterinf= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = inf.inflate(R.layout.group_list_row, null);
    finalViewchildheader= inf.inflate(R.layout.child_list_header, null);

    LinearLayoutgroupLayout= (LinearLayout) view.findViewById(R.id.group_layout_id);

    if(list.isGroupExpanded(groupPosition)){
        groupLayout.addView(childheader, newLinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    }else{
        groupLayout.removeView(childheader);
    }

Post a Comment for "Android Expandable Listview Customization On Child View"