-
-
Save moltak/10458814 to your computer and use it in GitHub Desktop.
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
View view = inflater.inflate(R.layout.expandable, container, false); | |
ExpandableAdapter adapter = new ExpandableAdapter(); | |
expandableListView.setAdapter(adapter); | |
setExpandableListViewHeight(expandableListView, -1); | |
expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { | |
@Override | |
public boolean onGroupClick(ExpandableListView parent, View v, int position, long id) { | |
setExpandableListViewHeight(parent, position); | |
return false; | |
} | |
}); | |
return view; | |
} |
private void setExpandableListViewHeight(ExpandableListView listView,
int group) {
ExpandableListAdapter listAdapter = (ExpandableListAdapter) listView.getExpandableListAdapter();
int totalHeight = 0;
int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(),
View.MeasureSpec.EXACTLY);
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
View groupItem = listAdapter.getGroupView(i, false, null, listView);
groupItem.measure(desiredWidth, View.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, View.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();
}
Please share me the setExpandableListViewHeight(expandableListView,-1) Method codes., Thanks in Advance
This works really fine below method
Perfectly Worked.
awesome, thank you!
Why use this line setExpandableListViewHeight(expandableListView, -1); ?
Because when I use this my ExpandabeListView is showing in scroll initially but it set normal when i expanded any item
remains lots of space before click on any group,after clicking everything ok
give me solution
Excelente lo de shobishani , me funciono al 100
I would only add after children loop
totalHeight += (listView.getDividerHeight() * (listAdapter.getChildrenCount(i) - 1));
I used this method on my extendedListView but at first unnecessary extra space remains in my activity. Then I clicked a group, and it fixed. How to fix this problem?
I solved it. You can use it.
https://gist.github.com/zeynep-turker/ee0f5917a4f230a8d1f424efa5834648
Please share me the setExpandableListViewHeight(expandableListView,-1) Method codes., Thanks in Advance