int child = ExpandableListView.getPackedPositionChild(packed);
static ExpandableListPosition obtainPosition(long packedPosition) { if (packedPosition == ExpandableListView.PACKED_POSITION_VALUE_NULL) { return null; } ExpandableListPosition elp = getRecycledOrCreate(); elp.groupPos = ExpandableListView.getPackedPositionGroup(packedPosition); if (ExpandableListView.getPackedPositionType(packedPosition) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { elp.type = CHILD; elp.childPos = ExpandableListView.getPackedPositionChild(packedPosition); } else { elp.type = GROUP; } return elp; }
@Override public boolean onContextItemSelected(MenuItem item) { ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo(); String title = ((TextView) info.targetView).getText().toString(); int type = ExpandableListView.getPackedPositionType(info.packedPosition); if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition); Toast.makeText(this, title + ": Child " + childPos + " clicked in group " + groupPos, Toast.LENGTH_SHORT).show(); return true; } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); Toast.makeText(this, title + ": Group " + groupPos + " clicked", Toast.LENGTH_SHORT).show(); return true; } return false; }
@Override public boolean onContextItemSelected(MenuItem item) { ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo(); String title = ((TextView) info.targetView).getText().toString(); int type = ExpandableListView.getPackedPositionType(info.packedPosition); if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition); Toast.makeText(this, title + ": Child " + childPos + " clicked in group " + groupPos, Toast.LENGTH_SHORT).show(); return true; } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); Toast.makeText(this, title + ": Group " + groupPos + " clicked", Toast.LENGTH_SHORT).show(); return true; } return false; }
@Override public void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount) { final long flatPos = getExpandableListPosition(firstVisibleItem); int groupPosition = ExpandableListView.getPackedPositionGroup(flatPos); int childPosition = ExpandableListView.getPackedPositionChild(flatPos); configureHeaderView(groupPosition, childPosition); }
static ExpandableHListPosition obtainPosition(long packedPosition) { if (packedPosition == ExpandableListView.PACKED_POSITION_VALUE_NULL) { return null; } ExpandableHListPosition elp = getRecycledOrCreate(); elp.groupPos = ExpandableListView.getPackedPositionGroup(packedPosition); if (ExpandableListView.getPackedPositionType(packedPosition) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { elp.type = CHILD; elp.childPos = ExpandableListView.getPackedPositionChild(packedPosition); } else { elp.type = GROUP; } return elp; }
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { int groupPosition = ExpandableListView.getPackedPositionGroup(id); if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { int childPosition = ExpandableListView.getPackedPositionChild(id); taskAdapter.setLongClickedSubTaskByPos(groupPosition, childPosition); } else { taskAdapter.setLongClickedTaskByPos(groupPosition); } return false; }
@Override protected void onLayout(boolean changed, int left, int top, int right,int bottom) { super.onLayout(changed, left, top, right, bottom); final long flatPostion = getExpandableListPosition(getFirstVisiblePosition()); final int groupPos = ExpandableListView.getPackedPositionGroup(flatPostion); final int childPos = ExpandableListView.getPackedPositionChild(flatPostion); int state = mAdapter.getHeaderState(groupPos, childPos); if (mHeaderView != null && mAdapter != null && state != mOldState) { mOldState = state; mHeaderView.layout(0, 0, mHeaderViewWidth, mHeaderViewHeight); } configureHeaderView(groupPos, childPos); }
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { int groupPosition = ExpandableListView.getPackedPositionGroup(id); if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { int childPosition = ExpandableListView.getPackedPositionChild(id); expandableTodoTaskAdapter.setLongClickedSubTaskByPos(groupPosition, childPosition); } else { expandableTodoTaskAdapter.setLongClickedTaskByPos(groupPosition); } registerForContextMenu(lv); return false; } });
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { int groupPosition = ExpandableListView.getPackedPositionGroup(id); if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { int childPosition = ExpandableListView.getPackedPositionChild(id); expandableTodoTaskAdapter.setLongClickedSubTaskByPos(groupPosition, childPosition); } else { expandableTodoTaskAdapter.setLongClickedTaskByPos(groupPosition); } registerForContextMenu(exLv); return false; } });
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { int itemType = ExpandableListView.getPackedPositionType(id); int childPosition; int groupPosition; if ( itemType == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { childPosition = ExpandableListView.getPackedPositionChild(id); groupPosition = ExpandableListView.getPackedPositionGroup(id); final Item item = (Item) mAdapter.getChild(groupPosition, childPosition); if (item instanceof AppItem) { showAppDetails(((AppItem) item).info); return true; } else if (item instanceof BookmarkItem) { removeBookark((BookmarkItem)item); return true; } else { return false; } } else if(itemType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { groupPosition = ExpandableListView.getPackedPositionGroup(id); return false; } else { return false; } } };
final int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition); final ObservationItem observationItem = controller.getListAdapter().getChild(groupPosition, childPosition);
private static String buildAdapterViewItemIndex(View child, ViewGroup group) { int index = ((AdapterView) group).getPositionForView(child); // ExpandableListView if (group instanceof ExpandableListView) { StringBuilder element = new StringBuilder(); String exListIndicator = ""; ExpandableListView _group = (ExpandableListView) group; long l = _group.getExpandableListPosition(index); int groupIndex; if (ExpandableListView.getPackedPositionType(l) == ExpandableListView.PACKED_POSITION_TYPE_NULL) { if (index < _group.getHeaderViewsCount()) { exListIndicator = "[header:" + index + "]";// header } else { groupIndex = index - (_group.getCount() - _group.getFooterViewsCount()); exListIndicator = "[footer:" + groupIndex + "]";// footer } } else { groupIndex = ExpandableListView.getPackedPositionGroup(l); int childIndex = ExpandableListView.getPackedPositionChild(l); if (childIndex != -1) { exListIndicator = "[group:" + groupIndex + ",child:" + childIndex + "]";// group/child } else { exListIndicator = "[group:" + groupIndex + "]";// group } } Log.d("ExpandableListViewItem", "@index = " + index + ", @exListIndicator = " + exListIndicator); return exListIndicator; } return "[" + index + "]"; }
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // Would prefer to have this context menu view managed internal to RecentTabsGroupView // Unfortunately, setting either onCreateContextMenuListener or onLongClickListener // disables the native onClick (expand/collapse) behaviour of the group view. ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; int type = ExpandableListView.getPackedPositionType(info.packedPosition); int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition); if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { mAdapter.getGroup(groupPosition).onCreateContextMenuForGroup(menu, mActivity); } else if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition); mAdapter.getGroup(groupPosition).onCreateContextMenuForChild(childPosition, menu, mActivity); } }
int child = ExpandableListView.getPackedPositionChild(packed);
protected Object getContextMenuSource(final View v, final ContextMenuInfo menuInfo) { Object source = null; if (menuInfo instanceof AdapterContextMenuInfo) { final AbsListView list = (AbsListView) v; final AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfo; source = list.getAdapter().getItem(mi.position); } else if (menuInfo instanceof ExpandableListContextMenuInfo) { final ExpandableListView list = (ExpandableListView) v; final ExpandableListAdapter adapter = list.getExpandableListAdapter(); final ExpandableListContextMenuInfo mi = (ExpandableListContextMenuInfo) menuInfo; final long pp = mi.packedPosition; final int group = ExpandableListView.getPackedPositionGroup(pp); final int child = ExpandableListView.getPackedPositionChild(pp); if (child >= 0) { source = adapter.getChild(group, child); } else { source = adapter.getGroup(group); } } return source; }
protected Object getContextMenuSource(final View v, final ContextMenuInfo menuInfo) { Object source = null; if (menuInfo instanceof AdapterContextMenuInfo) { final AbsListView list = (AbsListView) v; final AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfo; source = list.getAdapter().getItem(mi.position); } else if (menuInfo instanceof ExpandableListContextMenuInfo) { final ExpandableListView list = (ExpandableListView) v; final ExpandableListAdapter adapter = list.getExpandableListAdapter(); final ExpandableListContextMenuInfo mi = (ExpandableListContextMenuInfo) menuInfo; final long pp = mi.packedPosition; final int group = ExpandableListView.getPackedPositionGroup(pp); final int child = ExpandableListView.getPackedPositionChild(pp); if (child >= 0) { source = adapter.getChild(group, child); } else { source = adapter.getGroup(group); } } return source; }
@Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, view, menuInfo); // Bail if not working with expandable long-press, or if not child if (!(menuInfo instanceof ExpandableListContextMenuInfo)) return; final ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo; final int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition); final int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition); // Skip long-press on expandable parents if (childPosition == -1) return; final AccountDisplay account = (AccountDisplay)mAdapter.getGroup(groupPosition); final GroupDelta child = (GroupDelta)mAdapter.getChild(groupPosition, childPosition); // Ignore when selective syncing unsupported final int syncMode = getSyncMode(account); if (syncMode == SYNC_MODE_UNSUPPORTED) return; if (child != null) { showRemoveSync(menu, account, child, syncMode); } else { showAddSync(menu, account, syncMode); } }
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(Menu.NONE, 0, Menu.NONE, R.string.context_action_shortcut); menu.add(Menu.NONE, 1, Menu.NONE, R.string.context_action_launch); ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo)menuInfo; ExpandableListView list = (ExpandableListView) getView().findViewById(R.id.expandableListView1); switch(ExpandableListView.getPackedPositionType(info.packedPosition)) { case ExpandableListView.PACKED_POSITION_TYPE_CHILD: MyActivityInfo activity = (MyActivityInfo) list.getExpandableListAdapter().getChild(ExpandableListView.getPackedPositionGroup(info.packedPosition), ExpandableListView.getPackedPositionChild(info.packedPosition)); menu.setHeaderIcon(activity.icon); menu.setHeaderTitle(activity.name); menu.add(Menu.NONE, 2, Menu.NONE, R.string.context_action_edit); break; case ExpandableListView.PACKED_POSITION_TYPE_GROUP: MyPackageInfo pack = (MyPackageInfo) list.getExpandableListAdapter().getGroup(ExpandableListView.getPackedPositionGroup(info.packedPosition)); menu.setHeaderIcon(pack.icon); menu.setHeaderTitle(pack.name); break; } super.onCreateContextMenu(menu, v, menuInfo); }
final int type = ExpandableListView.getPackedPositionType(cmi.packedPosition); final int groupPosition = ExpandableListView.getPackedPositionGroup(cmi.packedPosition); final int childPosition = ExpandableListView.getPackedPositionChild(cmi.packedPosition);