I\'d like to have a listview in scrollview. This method is doing it almost perfect: https://stackoverflow.com/a/3495908/2811653
There is a bug when I enter more text in
Put your listview in a relative layout and your button in another layout. listview is itself scrollable so you don't need to put your listview in a scrollview. It is useless.
by putting the button in another layout, you will be able to scroll listview easily, and your button will be visible below the layout
Try this solution that I posted here.
If you do not want the ListView itself to scroll and just want the ListView's height to be such that all elements are shown, then you can create a subclass of ListView to accomplish this.
public class ListViewForEmbeddingInScrollView extends ListView {
public ListViewForEmbeddingInScrollView(Context context) {
super(context);
}
public ListViewForEmbeddingInScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ListViewForEmbeddingInScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 4, MeasureSpec.AT_MOST));
}
}
Manipulating the heightMeasureSpec to be AT_MOST with a very large size (Integer.MAX_VALUE >> 4) causes the ListView to measure all of its children up to the given (very large) height and set its height accordingly.
There is much discussion about this problem here including a lot of discussion as to whether or not is is appropriate to even do this. I don't have enough reputation to post my answer there but this is better than any of the solutions in that link. Perhaps someone with more reputation will run across this and post a solution on that other question that links back to this one.