In my application within a scroll view, I am using list view. But the list view is not scrolling. Can anyone suggest me what should i do.
I searched for it and find out that the list view don't scroll within scroll view.
Any solution?
You can create your own list view and set expand to false. Here is the sample class
public class ExpandableHeightListView extends ListView {
boolean expanded = false;
public ExpandableHeightListView(Context context) {
super(context);
}
public ExpandableHeightListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ExpandableHeightListView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
public boolean isExpanded() {
return expanded;
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// HACK! TAKE THAT ANDROID!
if (isExpanded()) {
int expandSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public void setExpanded(boolean expanded) {
this.expanded = expanded;
}
}
You can use like this your activity.clas
ExpandableHeightListView listview = (ExpandableHeightListView) findViewById(R.id.list);
listview.setExpanded(true);
In your layout file you can use ExpandableHeightListView at the place of list view within a scroll view. It will scroll.
Exclude ListView from ScrollView, because ListView already have scrolling mechanism in it.
Don't put a listview inside a scrollview.
The listview already handles scrolling so it doesn't need to be inside a scrollview.
You should change your layouts to reflect this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With