Android Expandablelistview Does Not Expand Or Receive Click Events
Solution 1:
I've also encountered similar problem like you. After a couple of days of investigation, I found that I did something wrong. So I fixed it to work correctly by making small change.
Let's look at the body of boolean onGroupClick(...) in setOnGroupClickListener. You've returned true that means "the click was handled"
You should return false if you want to expand. So I suggest you to do like this :
forumListView.setOnGroupClickListener(newOnGroupClickListener() {
@OverridepublicbooleanonGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
Log.d("onGroupClick:", "worked");
parent.expandGroup(groupPosition);
returnfalse;
}
});
in android.widget.ExpandableListView class, there is a method named boolean handleItemClick(View v, int position, long id) which is responsible for expanding/collapsing groups or passing on the click to the proper child.
/* It's a group click, so pass on event */if (mOnGroupClickListener != null) {
if (mOnGroupClickListener.onGroupClick(this, v,
posMetadata.position.groupPos, id)) {
posMetadata.recycle();
returntrue;
}
}
/* expanding/collapsing/other tasks... */if you implement onGroupClick to return true, the the code below 8th line will never be executed. (that means, groups will never be collapsed, expanded)
Hope my answer helped you :-) good luck!
Solution 2:
In case you have a widget on your list item, such as a Button, you may have to add android:focusable="false" to it. The Button was not allowing my list item to be clicked. That was the issue in my case.
Solution 3:
There are probably three things u need to check,
- check if u have any data available for the chid, cos if u dont have any data the child will not appear at all.
2.try removing if condition check while you using layout inflaters
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(ctx);
convertView = inflater.inflate(R.layout.forum_list_child_item_row, null);
}
you need to also pass
ViewgrouphereconvertView = inflater.inflate(R.layout.forum_list_child_item_row,parent, false);
Solution 4:
I know this was already answered, but try setting the base layout of whatever you're inflating to have the attribute:
android:descendantFocusability="blocksDescendants"Solution 5:
If your expandable listview parent has button or switch it doesn't get called i wasted whole day in this. So just use below code
android:focusable="false"android:focusableInTouchMode="false"Add this code inside toggle button,switch button or any which is on expandable listview
Post a Comment for "Android Expandablelistview Does Not Expand Or Receive Click Events"