Android ExpandableListView divider is invisible
Asked Answered
E

2

6

I am having the following ExpandableListView:

<ExpandableListView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/listView"
            android:groupIndicator="@android:color/transparent"
            android:background="@color/app_background"
            android:scrollingCache="false"
            android:choiceMode="none"
            android:divider="@color/gray_dark"
            android:dividerHeight="2dp"
            android:childDivider="@color/gray_dark"
            android:cacheColorHint="@color/app_background"/>

The problem that I have is that the expandable list view is not drawing the dividers or at least are not visible.. I am adding a custom view as Group view and also custom list items in my expandable adapter. Could this be a problem?

Does anyone know what can I do to enable the dividers for the list child?

Thank you in advance.

Elli answered 27/8, 2012 at 15:48 Comment(3)
Are you "adding" custom Views to the list through an Adapter or through something like ((ViewGroup) findViewById(R.id.listView)).addView(child)? If the latter, it won't work as you expect.Turnbull
I am adding custom views through an AdapterElli
I started having this problem when I upgraded the Android Studio from 4.1.2 to 2020.3.1, the divider's height started showing inconsistent values. I had to programmatically set to minimum 2: expandableListView.setDividerHeight(2);Destructible
E
14

It seems that I had an issue on my Expandable Adapter.. I was overridden the following method:

@Override
public boolean areAllItemsEnabled() {
    return true;
}

Instead of returning true I left the method to return false and that was the problem... So if anyone has this problem, check that method and make sure it returns true and not false.

Note that it is not necessary to override that method if you extend BaseExpandableListAdapter

Elli answered 28/8, 2012 at 15:28 Comment(2)
Great, this has been annoying me for a good hour or so :) For future reference, I also found I needed to return true for isChildSelectable()Russ
I agree with @sleeke, had to to both areAllItemsEnabled() and isChildSelectable() in order for it to stop being invisible.Warlock
M
0

I've never tried to mess with the dividers in the xml, I've always done it through code. Following is a snippet that sets the divider to red and has it fade out as it moves form the center to the edges. There is only one divider height call as that part affects both the group and the child.

import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;

// code to set up expandablelistview

int[] colors = {0, 0xFFFF0000, 0}; // red for the example 
getListView().setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors)); 
getListView().setChildDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors)); 
getListView().setDividerHeight(4); 
Macmahon answered 27/8, 2012 at 16:11 Comment(1)
Hmm, ok I will try to do it in code, though it would have been better if there was a way to do this in xml... I will try this tomorrow and seeElli

© 2022 - 2024 — McMap. All rights reserved.