Java Code Examples for android.widget.ExpandableListAdapter.getGroupView()

The following are Jave code examples for showing how to use getGroupView() of the android.widget.ExpandableListAdapter class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: StickyAnimatedExpandableGridView   File: StickyHeaderExpandableGridView.java   View Source Code Vote up 6 votes
@Override
public void setAdapter(ExpandableListAdapter adapter) {
    super.setAdapter(adapter);
    mAdapter = adapter;
    mHeaderView = adapter.getGroupView(0, false, null, this);
    boolean isBaseAdapter = adapter instanceof BaseExpandableListAdapter;
    if (cacheHeaderViews == null) {
        if (isBaseAdapter) {
            int typeCount = ((BaseExpandableListAdapter) adapter).getGroupTypeCount();
            cacheHeaderViews = new SparseArray<>(typeCount);
        }
        cacheHeaderViews = new SparseArray<>(1);
    }
    if (mHeaderView != null) {
        int groupType = 0;
        if (isBaseAdapter) {
            groupType = ((BaseExpandableListAdapter) adapter).getGroupType(0);
            cacheHeaderViews.put(groupType, mHeaderView);
        }
        cacheHeaderViews.put(groupType, mHeaderView);
    }
}
 
Example 2
Project: m-dan   File: Utils.java   View Source Code Vote up 5 votes
/**
 * Sets ExpandableListView height dynamically based on the height of the items.
 *
 * @param expandablelistView to be resized
 * @return true if the expandablelistView is successfully resized, false otherwise
 */
public static boolean setListViewHeightBasedOnItems(ExpandableListView expandablelistView) {

    ExpandableListAdapter expandableListAdapter = expandablelistView.getExpandableListAdapter();
    if (expandableListAdapter != null) {

        int numberOfGroups = expandableListAdapter.getGroupCount();
        int numberOfDividers = numberOfGroups;

        // Get total height of all items of all group expanded
        int totalItemsHeight = 0;

        for (int groupPos = 0; groupPos < numberOfGroups; groupPos++) {

            View item = expandableListAdapter.getGroupView(groupPos, expandablelistView.isGroupExpanded(groupPos), null, expandablelistView);
            item.measure(0, 0);
            totalItemsHeight += item.getMeasuredHeight();

            if(expandablelistView.isGroupExpanded(groupPos)) {
                totalItemsHeight += calculateHeightOfOneGroup(groupPos, expandableListAdapter, expandablelistView);
                numberOfDividers += expandableListAdapter.getChildrenCount(groupPos);
            }
        }

        // Get total height of all item dividers.
        int totalDividersHeight = expandablelistView.getDividerHeight() * numberOfDividers;

        // Set list height.
        ViewGroup.LayoutParams params = expandablelistView.getLayoutParams();
        params.height = totalItemsHeight + totalDividersHeight + 5;
        expandablelistView.setLayoutParams(params);
        expandablelistView.requestLayout();

        return true;
    } else {
        return false;
    }
}
 
Example 3
Project: lr_dialer   File: Common.java   View Source Code Vote up 5 votes
private void onScrollStateChanged(ExpandableListView elv, int scrollState)
{
	elv.setTag(AQuery.TAG_NUM, scrollState);
	if (scrollState == SCROLL_STATE_IDLE)
	{
		int first = elv.getFirstVisiblePosition();
		int last = elv.getLastVisiblePosition();
		int count = last - first;
		ExpandableListAdapter ela = elv.getExpandableListAdapter();
		for (int i = 0; i <= count; i++)
		{
			long packed = elv.getExpandableListPosition(i + first);
			int group = ExpandableListView.getPackedPositionGroup(packed);
			int child = ExpandableListView.getPackedPositionChild(packed);
			if (group >= 0)
			{
				View convertView = elv.getChildAt(i);
				Long targetPacked = (Long) convertView.getTag(AQuery.TAG_NUM);
				if (targetPacked != null && targetPacked.longValue() == packed)
				{
					if (child == -1)
					{
						ela.getGroupView(group, elv.isGroupExpanded(group), convertView, elv);
					}
					else
					{
						ela.getChildView(group, child, child == ela.getChildrenCount(group) - 1, convertView, elv);
					}
					convertView.setTag(AQuery.TAG_NUM, null);
				}
				else
				{
					//AQUtility.debug("skip!");
				}
			}
		}
	}
}
 
Example 4
Project: ocara   File: ListViewUtils.java   View Source Code Vote up 5 votes
/**
 * To compute the expandable listview for a given group.
 *
 * @param listView ExpandableListView
 * @param group    group
 */
public static void updateExpandableListViewHeight(ExpandableListView listView,
                                                  int group) {
    ExpandableListAdapter listAdapter = (ExpandableListAdapter) listView.getExpandableListAdapter();
    if (listAdapter == null) {
        // pre-condition
        return;
    }

    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getGroupCount(); i++) {
        View groupItem = listAdapter.getGroupView(i, false, null, listView);
        groupItem.measure(0, 0);

        totalHeight += groupItem.getMeasuredHeight();

        if (((listView.isGroupExpanded(i)) && (i != group))
                || ((!listView.isGroupExpanded(i)) && (i == group))) {
            for (int j = 0; j < listAdapter.getChildrenCount(i); j++) {
                View listItem = listAdapter.getChildView(i, j, false, null, listView);
                listItem.measure(0, 0);
                totalHeight += listItem.getMeasuredHeight();
            }
        }
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}
 
Example 5
Project: tehilim   File: Tools.java   View Source Code Vote up 5 votes
public static void setListViewHeight(ExpandableListView listView, int group) {
    ExpandableListAdapter listAdapter = listView.getExpandableListAdapter();
    int totalHeight = 0;
    int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(),
            MeasureSpec.AT_MOST);
    for (int i = 0; i < listAdapter.getGroupCount(); i++) {
        View groupItem = listAdapter.getGroupView(i, false, null, listView);
        groupItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);

        totalHeight += groupItem.getMeasuredHeight();

        if (((listView.isGroupExpanded(i)) && (i != group))
                || ((!listView.isGroupExpanded(i)) && (i == group))) {
            for (int j = 0; j < listAdapter.getChildrenCount(i); j++) {
                View listItem = listAdapter.getChildView(i, j, false, null,
                        listView);
                listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);

                totalHeight += listItem.getMeasuredHeight();

            }
        }
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    int height = totalHeight
            + (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1));
    if (height < 10)
        height = 200;
    params.height = height;
    listView.setLayoutParams(params);
    listView.requestLayout();
}
 
Example 6
Project: wordpress_app_android   File: StatsUIHelper.java   View Source Code Vote up 4 votes
public static void reloadGroupViews(final Context ctx,
                                    final ExpandableListAdapter mAdapter,
                                    final SparseBooleanArray mGroupIdToExpandedMap,
                                    final LinearLayout mLinearLayout,
                                    final int maxNumberOfItemsToshow) {
    if (ctx == null || mLinearLayout == null || mAdapter == null || mGroupIdToExpandedMap == null) {
        return;
    }

    int groupCount = Math.min(mAdapter.getGroupCount(), maxNumberOfItemsToshow);
    if (groupCount == 0) {
        mLinearLayout.removeAllViews();
        return;
    }

    int numExistingGroupViews = mLinearLayout.getChildCount();

    // remove excess views
    if (groupCount < numExistingGroupViews) {
        int numToRemove = numExistingGroupViews - groupCount;
        mLinearLayout.removeViews(groupCount, numToRemove);
        numExistingGroupViews = groupCount;
    }

    int bgColor = Color.TRANSPARENT;

    // add each group
    for (int i = 0; i < groupCount; i++) {
        boolean isExpanded = mGroupIdToExpandedMap.get(i);

        // reuse existing view when possible
        final View groupView;
        if (i < numExistingGroupViews) {
            View convertView = mLinearLayout.getChildAt(i);
            groupView = mAdapter.getGroupView(i, isExpanded, convertView, mLinearLayout);
            groupView.setBackgroundColor(bgColor);
            setViewBackgroundWithoutResettingPadding(groupView, i == 0 ? 0 : R.drawable.stats_list_item_background);
        } else {
            groupView = mAdapter.getGroupView(i, isExpanded, null, mLinearLayout);
            groupView.setBackgroundColor(bgColor);
            setViewBackgroundWithoutResettingPadding(groupView, i == 0 ? 0 : R.drawable.stats_list_item_background);
            mLinearLayout.addView(groupView);
        }

        // groupView is recycled, we need to reset it to the original state.
        ViewGroup childContainer = (ViewGroup) groupView.findViewById(R.id.layout_child_container);
        if (childContainer != null) {
            childContainer.setVisibility(View.GONE);
        }
        // Remove any other prev animations set on the chevron
        final ImageView chevron = (ImageView) groupView.findViewById(R.id.stats_list_cell_chevron);
        if (chevron != null) {
            chevron.clearAnimation();
            chevron.setImageResource(R.drawable.stats_chevron_right);
        }

        // add children if this group is expanded
        if (isExpanded) {
            StatsUIHelper.showChildViews(mAdapter, mLinearLayout, i, groupView, false);
        }

        // toggle expand/collapse when group view is tapped
        final int groupPosition = i;
        groupView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mAdapter.getChildrenCount(groupPosition) == 0) {
                    return;
                }
                boolean shouldExpand = !mGroupIdToExpandedMap.get(groupPosition);
                mGroupIdToExpandedMap.put(groupPosition, shouldExpand);
                if (shouldExpand) {
                    StatsUIHelper.showChildViews(mAdapter, mLinearLayout, groupPosition, groupView, true);
                } else {
                    StatsUIHelper.hideChildViews(groupView, groupPosition, true);
                }
            }
        });
    }
}
 
Example 7
Project: ExoPlayerDemo   File: Common.java   View Source Code Vote up 2 votes
private void onScrollStateChanged(ExpandableListView elv, int scrollState){
	
	elv.setTag(AQuery.TAG_NUM, scrollState);
	
	if(scrollState == SCROLL_STATE_IDLE){
		
		int first = elv.getFirstVisiblePosition();
		int last = elv.getLastVisiblePosition();
		
		int count = last - first;
		
		ExpandableListAdapter ela = elv.getExpandableListAdapter();
		
		for(int i = 0; i <= count; i++){
		
			long packed = elv.getExpandableListPosition(i + first);
			
			int group = ExpandableListView.getPackedPositionGroup(packed);
			int child = ExpandableListView.getPackedPositionChild(packed);
			
			if(group >= 0){
				
				View convertView = elv.getChildAt(i);
				Long targetPacked = (Long) convertView.getTag(AQuery.TAG_NUM);
				
				if(targetPacked != null && targetPacked.longValue() == packed){
				
					if(child == -1){
					
						ela.getGroupView(group, elv.isGroupExpanded(group), convertView, elv);
						
					}else{
						
						ela.getChildView(group, child, child == ela.getChildrenCount(group) - 1, convertView, elv);
						
					}
					convertView.setTag(AQuery.TAG_NUM, null);
				}else{
					//AQUtility.debug("skip!");
				}
				
			}
		
			
		}
		
		
		
	}
}
 
Example 8
Project: NeXT_pyp   File: Common.java   View Source Code Vote up 2 votes
private void onScrollStateChanged(ExpandableListView elv, int scrollState) {

		elv.setTag(Constants.TAG_NUM, scrollState);

		if (scrollState == SCROLL_STATE_IDLE) {

			int first = elv.getFirstVisiblePosition();
			int last = elv.getLastVisiblePosition();

			int count = last - first;

			ExpandableListAdapter ela = elv.getExpandableListAdapter();

			for (int i = 0; i <= count; i++) {

				long packed = elv.getExpandableListPosition(i + first);

				int group = ExpandableListView.getPackedPositionGroup(packed);
				int child = ExpandableListView.getPackedPositionChild(packed);

				if (group >= 0) {

					View convertView = elv.getChildAt(i);
					Long targetPacked = (Long) convertView
							.getTag(Constants.TAG_NUM);

					if (targetPacked != null
							&& targetPacked.longValue() == packed) {

						if (child == -1) {

							ela.getGroupView(group, elv.isGroupExpanded(group),
									convertView, elv);

						} else {

							ela.getChildView(group, child,
									child == ela.getChildrenCount(group) - 1,
									convertView, elv);

						}
						convertView.setTag(Constants.TAG_NUM, null);
					} else {
						// AQUtility.debug("skip!");
					}

				}

			}

		}
	}
 
Example 9
Project: NeXT_pyp   File: Common.java   View Source Code Vote up 2 votes
private void onScrollStateChanged(ExpandableListView elv, int scrollState) {

		elv.setTag(Constants.TAG_NUM, scrollState);

		if (scrollState == SCROLL_STATE_IDLE) {

			int first = elv.getFirstVisiblePosition();
			int last = elv.getLastVisiblePosition();

			int count = last - first;

			ExpandableListAdapter ela = elv.getExpandableListAdapter();

			for (int i = 0; i <= count; i++) {

				long packed = elv.getExpandableListPosition(i + first);

				int group = ExpandableListView.getPackedPositionGroup(packed);
				int child = ExpandableListView.getPackedPositionChild(packed);

				if (group >= 0) {

					View convertView = elv.getChildAt(i);
					Long targetPacked = (Long) convertView
							.getTag(Constants.TAG_NUM);

					if (targetPacked != null
							&& targetPacked.longValue() == packed) {

						if (child == -1) {

							ela.getGroupView(group, elv.isGroupExpanded(group),
									convertView, elv);

						} else {

							ela.getChildView(group, child,
									child == ela.getChildrenCount(group) - 1,
									convertView, elv);

						}
						convertView.setTag(Constants.TAG_NUM, null);
					} else {
						// AQUtility.debug("skip!");
					}

				}

			}

		}
	}
 
Example 10
Project: aceim   File: AQueryUtils.java   View Source Code Vote up 2 votes
private void onScrollStateChanged(ExpandableListView elv, int scrollState){
	
	elv.setTag(AQuery.TAG_NUM, scrollState);
	
	if(scrollState == SCROLL_STATE_IDLE){
		
		int first = elv.getFirstVisiblePosition();
		int last = elv.getLastVisiblePosition();
		
		int count = last - first;
		
		ExpandableListAdapter ela = elv.getExpandableListAdapter();
		
		for(int i = 0; i <= count; i++){
		
			long packed = elv.getExpandableListPosition(i + first);
			
			int group = ExpandableListView.getPackedPositionGroup(packed);
			int child = ExpandableListView.getPackedPositionChild(packed);
			
			if(group >= 0){
				
				View convertView = elv.getChildAt(i);
				//Long targetPacked = (Long) convertView.getTag(AQuery.TAG_NUM);						
				//if(targetPacked != null && targetPacked.longValue() == packed){
				
					if(child == -1){
					
						ela.getGroupView(group, elv.isGroupExpanded(group), convertView, elv);
						
					}else{
						
						ela.getChildView(group, child, child == ela.getChildrenCount(group) - 1, convertView, elv);
						
					}
					//convertView.setTag(AQuery.TAG_NUM, null);
				//}						
			}
		}
	}
}