如何在ExpandableListView [Android]中设置LongClick on group

Shu*_*udy 1 java android expandablelistview android-listview

我有一个ExanpdableLisView,我必须为子节点实现方法setOnChildClickListener,为组/父节点实现"LongClick".

我已经给了孩子一个,但我不知道如何实现LongClick.

这是代码 setOnChildClickListener

expListView.setOnChildClickListener(new OnChildClickListener() {

            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
                RosterEntry rentry = (RosterEntry) exListAdapter.getChild(groupPosition, childPosition);
                final String selected = rentry.getName();
                //Change Toast to make the new functionality
                Toast.makeText(getBaseContext(), selected, Toast.LENGTH_LONG).show();

                return true;
            }
        });
Run Code Online (Sandbox Code Playgroud)

但我不知道如何对Group/parent进行LongClick.

Y.S*_*Y.S 13

要长时间点击组或子视图,

getExpandableListView().setOnItemLongClickListener(new OnItemLongClickListener() {

    Override   
    public boolean onItemLongClick( AdapterView<?> parent, View view, int position, long id) {

        long packedPosition = m_expandableListView.getExpandableListPosition(position);

        int itemType = ExpandableListView.getPackedPositionType(packedPosition); 
        int groupPosition = ExpandableListView.getPackedPositionGroup(packedPosition);
        int childPosition = ExpandableListView.getPackedPositionChild(packedPosition);


        /*  if group item clicked */
        if (itemType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
            //  ...
            onGroupLongClick(groupPosition);
        }

        /*  if child item clicked */
        else if (itemType == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
            //  ...
            onChildLongClick(groupPosition, childPosition);
        }


        return false;
    }
});
Run Code Online (Sandbox Code Playgroud)

定义要执行任何操作的方法onGroupLongClick()onChildLongClick()方法.

试试这个.这会奏效.