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.