本文整理汇总了Java中android.widget.ExpandableListAdapter.getChildrenCount方法的典型用法代码示例。如果您正苦于以下问题:Java ExpandableListAdapter.getChildrenCount方法的具体用法?Java ExpandableListAdapter.getChildrenCount怎么用?Java ExpandableListAdapter.getChildrenCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.ExpandableListAdapter
的用法示例。
在下文中一共展示了ExpandableListAdapter.getChildrenCount方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setExpandedListViewHeightBasedOnChildren
import android.widget.ExpandableListAdapter; //导入方法依赖的package包/类
public static void setExpandedListViewHeightBasedOnChildren(ExpandableListView listView, int groupPosition) {
ExpandableListAdapter listAdapter = listView.getExpandableListAdapter();
if (listAdapter == null) {
return;
}
View listItem = listAdapter.getChildView(groupPosition, 0, true, null,
listView);
listItem.measure(0, 0);
int appendHeight = 0;
for (int i = 0; i < listAdapter.getChildrenCount(groupPosition); i++) {
appendHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height += appendHeight;
listView.setLayoutParams(params);
}
示例2: setCollapseListViewHeightBasedOnChildren
import android.widget.ExpandableListAdapter; //导入方法依赖的package包/类
public static void setCollapseListViewHeightBasedOnChildren(ExpandableListView listView, int groupPosition) {
ExpandableListAdapter listAdapter = listView.getExpandableListAdapter();
if (listAdapter == null) {
return;
}
View listItem = listAdapter.getChildView(groupPosition, 0, true, null,
listView);
listItem.measure(0, 0);
int appendHeight = 0;
for (int i = 0; i < listAdapter.getChildrenCount(groupPosition); i++) {
appendHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height -= appendHeight;
listView.setLayoutParams(params);
}
示例3: setListViewHeightBasedOnItems
import android.widget.ExpandableListAdapter; //导入方法依赖的package包/类
/**
* 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;
}
}
示例4: calculateHeightOfOneGroup
import android.widget.ExpandableListAdapter; //导入方法依赖的package包/类
/**
* Calculate the height of an expanded group dynamically based on the height of the items.
*
* @param groupPos position of the current group
* @param expandableListAdapter adapter of the expandableList
* @param parent the parent that this view will eventually be attached to
* @return true if the listView is successfully resized, false otherwise
*/
public static int calculateHeightOfOneGroup(int groupPos, ExpandableListAdapter expandableListAdapter, ViewGroup parent) {
int numberOfItems = expandableListAdapter.getChildrenCount(groupPos);
// Get total height of all items in the group
int totalItemsHeight = 0;
for (int itemPos = 0; itemPos < numberOfItems; itemPos++) {
boolean lastItem = false;
if(itemPos == numberOfItems-1){
lastItem = true;
}
// Supprimer le if si on veut garder un truc générique. Ici, le if sert à gérer la cutom expandable en plus des expandables classiques
View item;
if(expandableListAdapter instanceof com.orange.ease.idunnololz.widgets.AnimatedExpandableListView.AnimatedExpandableListAdapter){
item = ((AnimatedExpandableListView.AnimatedExpandableListAdapter) expandableListAdapter).getRealChildView(groupPos, itemPos, lastItem, null, parent);
}else{
item = expandableListAdapter.getChildView(groupPos, itemPos, lastItem, null, parent);
}
item.measure(0, 0);
totalItemsHeight += item.getMeasuredHeight();
}
return totalItemsHeight;
}
示例5: updateExpandableListViewHeight
import android.widget.ExpandableListAdapter; //导入方法依赖的package包/类
/**
* 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();
}
示例6: setListViewHeight
import android.widget.ExpandableListAdapter; //导入方法依赖的package包/类
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();
}