5

I use a ExpandableListView in my Android application an want to perfrom an action if the user clicks long on the group element, so I defined a OnLongClickListener in my BaseExpandableListAdapter extention. The listener works as aspected but the child elements does not expand anymore. Any ideas?

 public class ConnectionAdapter extends BaseExpandableListAdapter {
    ...
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView,  
                             ViewGroup parent) {
        // convertView is a LinearLayout
        convertView.setOnLongClickListener(new OnLongClickListener() {
            public boolean onLongClick(View v) {
                // my action here
                return true;
            }
        });
     }
     ...   
 }

2 Answers 2

4

You can set setOnItemLongClickListener on your expandablelistview. ExpandableListView.PACKED_POSITION_TYPE_GROUP is the id of a group, change it to ExpandableListView.PACKED_POSITION_TYPE_CHILD and you can manipulate with longclicks on group childs.

Something like that:

    pager_income = (ExpandableListView) findViewById(R.id.income_scroll);

    pager_income.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
                // Your code with group long click 

                return true;
            }

            return false;
        }
    });
1

The reason that your code is not further processing any other 'onClick' events is because you are passing a 'true' in your return. If you indicate that an event was handled, the OS stops attempting to further process any further events. To have it process THIS event, and also expand, then you need to change the return to false instead of true

2
  • 4
    I have tried returning false. But the same issue persisit for me also. The group will not expand after implementing onLongClicklistener for convertview Sep 24, 2013 at 8:43
  • I have the same issue, as soon as I implement a long click listener on my group item, the short click (to expand the group) stops working... any help appreciated. Sep 4, 2014 at 3:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.