android expandablelistview does not expand or receive click events

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(new OnGroupClickListener() {
    @Override
    public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            Log.d("onGroupClick:", "worked");
            parent.expandGroup(groupPosition);
            return false;
        }
    });

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();
                 return true;
             }
         }

  /* 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!

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.

There are probably three things u need to check,

  1. 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);
    }
  1. you need to also pass Viewgroup here

      convertView = inflater.inflate(R.layout.forum_list_child_item_row,parent, false);
    

Leave a Comment