@Overridepublic Object getChild(int groupPosition, int childPosition) {
return arrayItemSP.get(groupPosition).get(childPosition);
}
@Overridepublic long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Overridepublic long getGroupId(int groupPosition) {
return groupPosition;
}
lvSP.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long packedId) {
// NOTE: the position is NOT group position, it is the position of the TOTAL OPEN ITEM (groups + childs) until this position !!
// NOTE: use static ExpandableListView.getPackedPositionType(long packedId) !!! int type = ExpandableListView.getPackedPositionType(packedId);
int groupPosition = ExpandableListView.getPackedPositionGroup(packedId);
switch (type) {
case ExpandableListView.PACKED_POSITION_TYPE_GROUP: {
/* if group item clicked */ Toast.makeText(SanphamActivity.this,"Vị tri group "+groupPosition,Toast.LENGTH_SHORT).show();
// consume this event and do NOT let Android do more process on it (expand/collapse group) return true;
}
case ExpandableListView.PACKED_POSITION_TYPE_CHILD: {
/* if child item clicked */ int childPosition = ExpandableListView.getPackedPositionChild(packedId);
Toast.makeText(SanphamActivity.this,"Vị tri child "+childPosition,Toast.LENGTH_SHORT).show();
// consume this event and do NOT let Android do more process on it (expand/collapse group) return true;
}
}
return false;
}
});
0 comments:
Post a Comment