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 void onCreateContextMenu (final @Nonnull ContextMenu menu, final @Nonnull View view, final @Nonnull ContextMenuInfo menuInfo) { final ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo)menuInfo; final int type = ExpandableListView.getPackedPositionType(info.packedPosition); int menuId = 0; switch (type) { case ExpandableListView.PACKED_POSITION_TYPE_GROUP: menuId = R.menu.observations_context_menu; break; case ExpandableListView.PACKED_POSITION_TYPE_CHILD: menuId = R.menu.observation_items_context_menu; break; default: return; } getMenuInflater().inflate(menuId, menu); }
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; MenuInflater inflater = getActivity().getMenuInflater(); int type = ExpandableListView.getPackedPositionType(info.packedPosition); if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { inflater.inflate(R.menu.context_menu_novel_details_volume, menu); } else if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { inflater.inflate(R.menu.context_menu_novel_details_chapter, menu); } }
@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; }
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; int type = ExpandableListView.getPackedPositionType(info.packedPosition); MenuInflater inflater = this.getMenuInflater(); menu.setHeaderView(Helper.getMenuHeader(getBaseContext(), getBaseContext().getString(R.string.select_option))); // context menu for child items if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { inflater.inflate(R.menu.todo_subtask_long_click, menu); } else { // context menu for group items inflater.inflate(R.menu.todo_task_long_click, menu); } }
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 void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; int type = ExpandableListView.getPackedPositionType(info.packedPosition); MenuInflater inflater = getActivity().getMenuInflater(); menu.setHeaderView(Helper.getMenuHeader(getContext(), getContext().getString(R.string.select_option))); // context menu for child items if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { inflater.inflate(R.menu.todo_subtask_long_click, menu); } else { // context menu for group items inflater.inflate(R.menu.todo_task_long_click, menu); } }
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; int type = ExpandableListView.getPackedPositionType(info.packedPosition); MenuInflater inflater = this.getMenuInflater(); menu.setHeaderView(Helper.getMenuHeader(getBaseContext(), getBaseContext().getString(R.string.select_option))); inflater.inflate(R.menu.deleted_task_long_click, menu); }
@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 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 type = ExpandableListView.getPackedPositionType(info.packedPosition); final int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);
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); } }
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));
@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); }
if (menuInfo instanceof ExpandableListContextMenuInfo) { final ExpandableListContextMenuInfo cmi = (ExpandableListContextMenuInfo) menuInfo; final int type = ExpandableListView.getPackedPositionType(cmi.packedPosition); final int groupPosition = ExpandableListView.getPackedPositionGroup(cmi.packedPosition); final int childPosition = ExpandableListView.getPackedPositionChild(cmi.packedPosition);