ExpandableListView click handling

39 views Asked by At

Two Questions:

  1. I want to allow the user to long-click on child items ONLY if they're in the FIRST group of my expandable list view. Under any other group, this should not be allowed. How can I do this?

  2. I want the user to be allowed to long-click ALL group items EXCEPT the first one.

I'm going to be handling both questions in the ExpandableListViews onItemLongClickListener.

Currently I have:

    @Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    if (bunchesExpListView.getPackedPositionType(id)==ExpandableListView.PACKED_POSITION_TYPE_GROUP) { // long click on bunch
        BunchLongClickDialog bunchLongClickDialog = new BunchLongClickDialog();
        Bundle bundle = new Bundle();
        bundle.putInt("group_position", position);
        bunchLongClickDialog.setArguments(bundle);
        bunchLongClickDialog.show(getFragmentManager(), "bunch_long_click_dialog");
    }
    return true;
}

This only tells if I'm clicking a group, it doesn't check for the group being the first one, and does nothing to address the first question.

1

There are 1 answers

0
Brandon On BEST ANSWER

autobot_101 helped me answer my question with his post here.

Essentially you can use getPackedPosition to obtain the groupPosition and childPosition before doing any conditionals!