List of usage examples for android.widget ExpandableListView getPackedPositionForChild
public static long getPackedPositionForChild(int groupPosition, int childPosition)
From source file:com.granita.tasks.TaskListFragment.java
public void setActivatedItem(int groupPosition, int childPosition) { if (groupPosition != ExpandableListView.INVALID_POSITION && groupPosition < mAdapter.getGroupCount() && childPosition != ExpandableListView.INVALID_POSITION && childPosition < mAdapter.getChildrenCount(groupPosition)) { try {// www. j av a2 s . c o m mExpandableListView.setItemChecked(mExpandableListView.getFlatListPosition( ExpandableListView.getPackedPositionForChild(groupPosition, childPosition)), true); } catch (NullPointerException e) { // for now we just catch the NPE until we've found the reason // just catching it won't hurt, it's just that the list selection won't be updated properly // FIXME: find the actual cause and fix it } } }
From source file:org.totschnig.myexpenses.fragment.CategoryList.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor c) { if (getActivity() == null) return;/*from w w w.jav a2s .c om*/ int id = loader.getId(); ProtectedFragmentActivity ctx = (ProtectedFragmentActivity) getActivity(); ActionBar actionBar = ctx.getSupportActionBar(); switch (id) { case SUM_CURSOR: boolean[] seen = new boolean[2]; c.moveToFirst(); while (c.isAfterLast() == false) { int type = c.getInt(c.getColumnIndex(KEY_TYPE)); updateSum(type > 0 ? "+ " : "- ", type > 0 ? incomeSumTv : expenseSumTv, c.getLong(c.getColumnIndex(KEY_SUM))); c.moveToNext(); seen[type] = true; } //if we have no income or expense, there is no row in the cursor if (!seen[1]) updateSum("+ ", incomeSumTv, 0); if (!seen[0]) updateSum("- ", expenseSumTv, 0); break; case DATEINFO_CURSOR: c.moveToFirst(); actionBar.setSubtitle(mGrouping.getDisplayTitle(ctx, mGroupingYear, mGroupingSecond, c)); thisYear = c.getInt(c.getColumnIndex(KEY_THIS_YEAR)); thisMonth = c.getInt(c.getColumnIndex(KEY_THIS_MONTH)); thisWeek = c.getInt(c.getColumnIndex(KEY_THIS_WEEK)); thisDay = c.getInt(c.getColumnIndex(KEY_THIS_DAY)); maxValue = c.getInt(c.getColumnIndex(KEY_MAX_VALUE)); break; case SORTABLE_CURSOR: mGroupCursor = c; mAdapter.setGroupCursor(c); if (ctx.helpVariant.equals(ManageCategories.HelpVariant.distribution)) { if (c.getCount() > 0) { if (lastExpandedPosition == -1) { mChart.setVisibility(showChart ? View.VISIBLE : View.GONE); setData(c, mMainColors); highlight(0); if (showChart) mListView.setItemChecked( mListView.getFlatListPosition(ExpandableListView.getPackedPositionForGroup(0)), true); } } else { mChart.setVisibility(View.GONE); } } if (mAccount != null) { actionBar.setTitle(mAccount.label); } invalidateCAB(); //only need to do this for group since children's cab does not depnd on cursor break; default: //check if group still exists if (mAdapter.getGroupId(id) != 0) { mAdapter.setChildrenCursor(id, c); if (ctx.helpVariant.equals(ManageCategories.HelpVariant.distribution)) { long packedPosition; if (c.getCount() > 0) { mSubColors = getSubColors(mMainColors.get(id % mMainColors.size())); setData(c, mSubColors); highlight(0); packedPosition = ExpandableListView.getPackedPositionForChild(id, 0); } else { packedPosition = ExpandableListView.getPackedPositionForGroup(id); if (!chartDisplaysSubs) {//check if a loader running concurrently has already switched to subs highlight(id); } } if (showChart && id == lastExpandedPosition) { //if user has expanded a new group before loading is finished, getFlatListPosition //would run in an NPE mListView.setItemChecked(mListView.getFlatListPosition(packedPosition), true); } } } } }