packed = ExpandableListView.getPackedPositionForChild(groupPosition, childPosition);
public long getPackedPosition() { if (type == CHILD) { return ExpandableListView.getPackedPositionForChild(groupPos, childPos); } else { return ExpandableListView.getPackedPositionForGroup(groupPos); } }
/** * @return list of indexes of all checked child items */ public List<Integer> getCheckedPositions() { List<Integer> selected = new ArrayList<>(); for (int i = 0; i < expandableList.groups.size(); i++) { if (expandableList.groups.get(i) instanceof CheckedExpandableGroup) { CheckedExpandableGroup group = (CheckedExpandableGroup) expandableList.groups.get(i); for (int j = 0; j < group.getItemCount(); j++) { if (group.isChildChecked(j)) { long packedPosition = ExpandableListView.getPackedPositionForChild(i, j); selected.add(expandableList.getFlattenedChildIndex(packedPosition)); } } } } return selected; }
@Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { long packedPositionForChild = mEl.getPackedPositionForChild(groupPosition, childPosition); // int packedPositionChild = mEl.getPackedPositionChild(packedPositionForChild); int flatListPosition = mEl.getFlatListPosition(packedPositionForChild); Log.d(TAG, "Child- " + flatListPosition + " - " + packedPositionForChild); Toast.makeText(BasicExpandableListView.this, "group=" + groupPosition + "-child=" + childPosition, Toast.LENGTH_SHORT).show(); return false; } }
long getPackedPosition() { if (type == CHILD) return ExpandableListView.getPackedPositionForChild( groupPos, childPos ); else return ExpandableListView.getPackedPositionForGroup(groupPos); }
@Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { final BaseActivity activity = BaseActivity.get(RootsFragment.this); final Item item = (Item) mAdapter.getChild(groupPosition, childPosition); if (item instanceof RootItem) { int index = parent.getFlatListPosition(ExpandableListView.getPackedPositionForChild(groupPosition, childPosition)); parent.setItemChecked(index, true); activity.onRootPicked(((RootItem) item).root, true); Bundle params = new Bundle(); params.putString("type", ((RootItem) item).root.title); AnalyticsManager.logEvent("navigate", ((RootItem) item).root, params); } else if (item instanceof AppItem) { activity.onAppPicked(((AppItem) item).info); } else { throw new IllegalStateException("Unknown root: " + item); } return false; } };
packed = ExpandableListView.getPackedPositionForChild(groupPosition, childPosition);
public void onCurrentRootChanged() { if (mAdapter == null || mList == null) return; final RootInfo root = ((BaseActivity) getActivity()).getCurrentRoot(); for (int i = 0; i < mAdapter.getGroupCount(); i++) { for (int j = 0; j < mAdapter.getChildrenCount(i); j++) { final Object item = mAdapter.getChild(i,j); if (item instanceof RootItem) { final RootInfo testRoot = ((RootItem) item).root; if (Objects.equal(testRoot, root)) { try { long id = ExpandableListView.getPackedPositionForChild(i, j); int index = mList.getFlatListPosition(id); //mList.setSelection(index); mList.setItemChecked(index, true); } catch (Exception e){ CrashReportingManager.logException(e); } return; } } } } }