0

I have a list view inside a scroll view.

To make it work I have created a custom list view from here http://www.londatiga.net/it/programming/android/make-android-listview-gridview-expandable-inside-scrollview/

but this is also not working when there is single item in listview. I am not able to scroll in case of single iteam.

Update: ExpandableHeightListView.java

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ListView;

/**
 * Created by hariram on 10/28/15.
 */
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;
    }
}

Now I am using this ExpandableHeightListView instead of list view like

ExpandableHeightListView listView = (ExpandableHeightListView) getView().findViewById(R.id.expandablelistview);
        listView.setExpanded(true);
        CustomAdapter customAdapter = new CustomAdapter( getActivity(), resultList);
        listView.setAdapter(customAdapter);

It's work fine when there is more than one item in list, but it doesn't work in case of single item. I am not able to scrol in case of single listing.

Hari Ram
  • 3,098
  • 5
  • 23
  • 30
  • `I have a list view inside a scroll view.` Which, itself, is a cause of troubles. Every combination of nested scrollable Views will produce weird behaviours. – Phantômaxx Nov 02 '15 at 11:43
  • but here this is my need, it will be great if you can suggest some solution for it. – Hari Ram Nov 02 '15 at 11:45
  • Please post the code you tried. It will make it easier for us to triage. – Eric Nov 02 '15 at 11:46
  • 2
    In the link you provided, the author mentions a solution provided by @NeilTraft: http://stackoverflow.com/questions/4523609/grid-of-images-inside-scrollview/4536955#4536955. Maybe ask him, who has experience in messing with nested scrollables? By the way, in the video is shown a normal ExpandableListView... which doesn't need a ScrollView to scroll. – Phantômaxx Nov 02 '15 at 11:48
  • 1
    @Eric I have updated code in question. – Hari Ram Nov 02 '15 at 11:56

0 Answers0