Android: long click on the child views of a ExpandableListView?

前端 未结 5 703
星月不相逢
星月不相逢 2020-12-02 06:41

ExpandableListView has a setOnChildClickListener method, but lacks of setOnChildLongClickListener method.

When I added setOnL

5条回答
  •  执笔经年
    2020-12-02 07:16

    I know this answer may be no need, but I have similar situation and non of these answer solve my problem. So I post mine in case someone may need it. Hope all you guys don't mind.

    @Override
                    public boolean onItemLongClick(AdapterView parent, View childView, int flatPos, long id) {
                         if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
                                final ExpandableListAdapter adapter = ((ExpandableListView) parent).getExpandableListAdapter();
                                long packedPos = ((ExpandableListView) parent).getExpandableListPosition(flatPos);
                                int groupPosition = ExpandableListView.getPackedPositionGroup(packedPos);
                                int childPosition = ExpandableListView.getPackedPositionChild(packedPos);
    
                            // do whatever you want with groupPos and childPos here - I used these to get my object from list adapter.
                        return false;
                    }
    

    Edit This solution for Listview was long time ago. I highly recommend to move to RecyclerView now.

提交回复
热议问题