Can you help me identify why there is a space between the group and the child? In my case I want spaces between all groups and the child should be right below the group with no space (but of course space to the next group. My problem looks like this:
I have set the Group divider to this drawable (expandable_list_group_divider):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="10dp"/>
</shape>
And the child divider to this (@drawable/expandable_list_child_divider):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="0dp"/>
</shape>
I have defined the layout like this in the xml(it is a compund control):
<com.jws.MyExpandableListView
android:id="@+id/expList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:scrollbars="none"
android:divider="@drawable/expandable_list_group_divider"
android:childDivider="@drawable/expandable_list_child_divider"/>
The custom view class:
public class MyExpandableListView extends ExpandableListView {
protected ArrayList<Departure> departures;
public MyExpandableListView(Context context, AttributeSet attrs) {
super(context, attrs);
setGroupIndicator(null);
setChildIndicator(null);
setHorizontalFadingEdgeEnabled(true);
setVerticalFadingEdgeEnabled(true);
setFadingEdgeLength(60);
departures = new ArrayList<Departure>();
this.setAdapter(new MyExpandableListAdapter(context, this, departures));
}
}
And finally the expandable list adapter
public class DeparturesExpandableListAdapter extends BaseExpandableListAdapter {
private final int DIVIDER_HEIGHT = 20;
private LayoutInflater inflater;
private ArrayList<Departure> departures;
private Context context;
private ExpandableListView expListView;
public DeparturesExpandableListAdapter(Context context, ExpandableListView expListView, ArrayList<Departure> departures)
{
this.context = context;
inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
this.departures = departures;
this.expListView = expListView;
}
// This Function used to inflate parent rows view
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parentView)
{
final Departure departure = departures.get(groupPosition);
if(!isExpanded)
expListView.setDividerHeight(DIVIDER_HEIGHT);
else
expListView.setDividerHeight(-4);
expListView.setFooterDividersEnabled(false);
// Inflate grouprow.xml file for parent rows
convertView = inflater.inflate(R.layout.view_departure_overview, parentView, false);
//Data handling in the view...
return convertView;
}
// This Function used to inflate child rows view
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parentView)
{
final Departure departure = departures.get(groupPosition);
if(isLastChild)
expListView.setDividerHeight(DIVIDER_HEIGHT);
// Inflate childrow.xml file for child rows
convertView = inflater.inflate(R.layout.view_departure_details, parentView, false);
//Data handling...
return convertView;
}
@Override
public Object getChild(int groupPosition, int childPosition)
{
return departures.get(groupPosition);
}
//Call when child row clicked
@Override
public long getChildId(int groupPosition, int childPosition)
{
return childPosition;
}
@Override
public int getChildrenCount(int groupPosition)
{
return 1;
}
@Override
public Object getGroup(int groupPosition)
{
return departures.get(groupPosition);
}
@Override
public int getGroupCount()
{
if(departures != null)
return departures.size();
return 0;
}
//Call when parent row clicked
@Override
public long getGroupId(int groupPosition)
{
return groupPosition;
}
@Override
public void notifyDataSetChanged()
{
// Refresh List rows
super.notifyDataSetChanged();
}
@Override
public boolean isEmpty()
{
return ((departures == null) || departures.isEmpty());
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition)
{
return false;
}
@Override
public boolean hasStableIds()
{
return false;
}
@Override
public boolean areAllItemsEnabled()
{
return true;
}
}
Image for comments:
In order to remove dividers just from the child views and not between the parents in the expandable List:
add android:childDivider="#00000000" in the ExapandableListView attributes in XML:
<ExpandableListView
android:id="@+id/elv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:childDivider="#00000000"
android:dividerHeight="0dp"
/>
Refer http://qtcstation.com/2011/03/working-with-the-expandablelistview-part-1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With