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?

- 490
- 7
- 22
-
1Well I havent personally used that class, but what are you doing that it does not call `getChildView()`. My assumption would be that it is called when it needs to prepare itself to display a `View`. So if the parent is not expanded there would be no reason for it to be called since it knows it doesn't need to show. But again, what conditions are you testing this in? – Andy Aug 09 '13 at 17:53
-
I've got the resources of the relevant code at: [StackOverflow question](http://stackoverflow.com/questions/16569387/expandableview-inside-another-expandableview-wont-inflate-children). Hope it answers your question – D.Ginzbourg Aug 09 '13 at 18:07
-
I know one condition for sure, and it's if the `childrenCount` returns 0 it won't call the function (for obvious reasons) – D.Ginzbourg Aug 09 '13 at 18:19
-
Hmm, I see why you are asking this question. Before I even bother giving you some advice, how are you verifying that `getChildView` is not being called. debugger or logging? – Andy Aug 09 '13 at 18:43
-
Debugger, I already see where this is going. I should use logging, correct? – D.Ginzbourg Aug 10 '13 at 08:54
-
I've used a small dialog to pop up when the `getChildView` is called. It never popped up. I've tested it on `getGroupView` and it did pop when that method was called. – D.Ginzbourg Aug 10 '13 at 09:27
-
Well no. You can look at the source of ExpandableListAdapter. Its in your android sdk folder. Just look for the examples of when its called. It seems if its never called you are not linking something correctly. My guess is since you are using custom views. Basically see what the source does and figure that out in combo with debugging. Logging is ok but debugging gives you a bit more power in seeing whats going on. A good way to see if its your implementation is to create a simple example without any custom views and debug that to see what is called when. – Andy Aug 11 '13 at 20:14
3 Answers
is called when you have more than 1 item in groups and in childs, i mean when getGroupCount returns a value greater than 0

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

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