今天用到ExpandableListView,需要用到ExpandableListView 子View的长按,但是没有对应的方法可调。
网上查了一下,并没有查到完美又简洁的方法,后来还是朋友给我找到了答案,做个记录。
expandableListV.setOnItemLongClickListener(new OnItemLongClickListener()
{
public boolean onItemLongClick(AdapterView<?> parent, View childView, int flatPos, long id)
{
if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD)
{
long packedPos = ((ExpandableListView) parent).getExpandableListPosition(flatPos);
int groupPosition = ExpandableListView.getPackedPositionGroup(packedPos);
int childPosition = ExpandableListView.getPackedPositionChild(packedPos);
showDeleteAlertDialog((AccountInfo) expAdapter.getChild(groupPosition, childPosition));
return true;
}
return false;
}
});