ExpandableListView items clickable

1

Does anyone know how I can make items in an ExpandableListView clickable?

I've implemented this template: How do an Expandable ListView? and now I would like to be able to click on the items and open a new activity or fragment.

    
asked by anonymous 07.06.2017 / 15:32

1 answer

1

You should indicate to the ExpandableListView an OnChildClickListener to use / call whenever an item is clicked:

expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

    @Override
    public boolean onChildClick(ExpandableListView parent, View v,
                                int groupPosition, int childPosition, long id) {

        //abra aqui a nova Activiy

        return true;
    }
});

The groupPosition parameter receives the index of the group whose item ( childPosition ) was clicked. Based on these two values open the new activity.

    
07.06.2017 / 16:25