Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ExpandableListView long group click listener prevent expand

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;
            }
        });
     }
     ...   
 }
like image 680
CannyDuck Avatar asked Feb 23 '12 21:02

CannyDuck


1 Answers

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;
        }
    });
like image 91
Magnus TechApple Avatar answered Sep 27 '22 16:09

Magnus TechApple