Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll feature of listview within scroll view

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?

like image 789
Sandy Avatar asked Dec 18 '13 13:12

Sandy


3 Answers

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.

like image 154
Code Hunter Avatar answered Oct 23 '22 11:10

Code Hunter


Exclude ListView from ScrollView, because ListView already have scrolling mechanism in it.

like image 5
Arfan Mirza Avatar answered Oct 23 '22 11:10

Arfan Mirza


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.

like image 1
Dazzy_G Avatar answered Oct 23 '22 12:10

Dazzy_G