On what conditions getChildView() is called in ExpandableListAdapter

◇◆丶佛笑我妖孽 提交于 2019-12-07 07:57:24

问题


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?


回答1:


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




回答2:


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."




回答3:


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" />



来源:https://stackoverflow.com/questions/18152629/on-what-conditions-getchildview-is-called-in-expandablelistadapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!