0

I've to use listView inside a scrollView , for some reasons I can't use addHeader for addFooter .

When I set adapter to my listView , I change it heights but it's not working properly .

This is my code :

lv.setAdapter(ladap);
                    int totalHeight = 0;
                    for (int size = 0; size < ladap.getCount(); size++) {
                        View listItem = ladap.getView(size, null, lv);
                        listItem.measure(0, 0);
                        totalHeight += listItem.getMeasuredHeight();
                    }
                    ViewGroup.LayoutParams params = lv.getLayoutParams();
                    params.height = totalHeight + (lv.getDividerHeight() * (ladap.getCount() - 1));
                    lv.setLayoutParams(params);
                    lv.requestLayout();

This is the result :

enter image description here

as you can see, the listview is finished in the middle of the page but it still scrolls alot .

How to make it right ?

1
  • 2
    dont use a list inside a scroll view , the list view has a build in scroll. Also, try to replace list view with recyclerview for better performance Commented Jul 21, 2015 at 14:43

1 Answer 1

2

You don't need to use a ScrollView with a ListView. As stated in the Android Dev docs:

You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.