I am currently trying to use a ListView inside of a ScrollView. I know from what I\'ve read that this is looked down upon, but I\'m trying to get the ListView to expand com
I took the function from djunod's answer (the function in static class)
calculate listview size
and change ondraw method as follow. it works after delete operations successfully.
here is my final class
class ExpandedListView extends ListView {
private android.view.ViewGroup.LayoutParams params;
private int old_count = 0;
public ExpandedListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
if (getCount() != old_count) {
params = getLayoutParams();
old_count = getCount();
int totalHeight = 0;
for (int i = 0; i < getCount(); i++) {
this.measure(0, 0);
totalHeight += getMeasuredHeight();
}
params = getLayoutParams();
params.height = totalHeight + (getDividerHeight() * (getCount() - 1));
setLayoutParams(params);
}
super.onDraw(canvas);
}
}
now my listview expands after row insert without scrolling. and after row delete this code calculates the correct size for listview. i don't know how it is working. but it is working. BR