Question

Can somebody tell me how to make an empty space between the groups of Expandable ListView. I tried many solutions but whenever I give height to divider it always increase the height of child divider too. I tried separately android:divider="@drawable/group_separator" and android:childDivider="@drawable/child_separator" and also tried to set the height programmatically separately in getChildView and in getGroupView but the same result. It always increase the space between child divider too but i just want to make space only between the groups even if there no item between them. Like to give the space of 40dp even if there is no item just like in the below image. Any help will be highly appreciated. Thanks in advance.

enter image description here

and after I applied the divider height it become like

enter image description here

Était-ce utile?

La solution

Answering to my own question so that anybody else may happen this problem so here is a solution after trying to much.I have done it through a single condition by just checking that if the group has no child then it should set the white layout that will be shown as a white blank space and no other things like padding, dividers or margin needed. just like in the below code in getGroupView() and you don't have to do anything else. The layout (blank_white_layout) I use is just a relativelayout having white background and you can give it height according to your needs.

if (getChildrenCount(groupPosition) == 0) {
            view = inflater.inflate(R.layout.blank_white_layout, null);
        }

and below is the complete getGroupView code in my adapter class

public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
            ViewGroup parent) {

        if (groupPosition == 0 ) {
            convertView = inflater.inflate(R.layout.group_layout1, null);
        }

        if (getChildrenCount(groupPosition) == 0) {
            convertView = inflater.inflate(R.layout.blank_white_layout, null);
        }else{
            convertView = inflater.inflate(R.layout.group_layout2, null);
        }
        TextView text1 = (TextView) convertView.findViewById(android.R.id.text1);
        return convertView;
    }

Autres conseils

From your getView() method detect the rows that you want to separate( by position and type) and just add to them padding or margin, very simple.

Just make sure to remove that padding or margin when the listview recycles that view.

Create separate xml layout for group and child views. Set padding to the group layout xml file.

Simply add this tag in the group2 xml view.

 android:layout_marginTop="40dp"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top