In my app, getChildView() inside my ExpandableListAdapter isn't being called while the adapter returns the correct child count (when getChildrenCount() is called). My question is; what are the conditions that need to be met, in order to have ExpandableListAdapter inflate its children?

有帮助吗?

解决方案

is called when you have more than 1 item in groups and in childs, i mean when getGroupCount returns a value greater than 0

其他提示

getGroupCount() method tells you how many groups will be there in you ExpandableListView and getChildrenCount(int groupPosition) method tells you how many child will be there for the respective group. So untill getChildrenCount method returns 1 or greater than 1 value, till than no child views will be visible.

One more thing which is also really matters when your child Views not getting visible is "height of Expandable Listview must be match_parent, if your expandable list view is within any other layout then that layout height should also be match_parent."

Your problem is not with the getChildView() my friend, It is definitely with the layout.

The exact problem is with the android:layout_height="" of your expandable list view that cuts of the childs.

Use this as the layout :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFFFFF"
tools:context="/*your activity*/" >

<ExpandableListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:childDivider="@android:color/transparent"
    android:dividerHeight="0dp" />

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top