0

I used listview inside scrollview and used this code to update listview height:

// method to expand the height of listview
public void updateListViewHeight(ListView list) {
    CustomeAdapter myListAdapter = (CustomeAdapter) list.getAdapter();
    if (myListAdapter == null) {
        return;
    }
    // get listview height
    int totalHeight = 0;
    // int adapterCount = myListAdapter.getCount();
    for (int size = 0; size < Math.max(shoutsList.size(), postsList.size()); size++) {
        View listItem = myListAdapter.getView(size, null, list);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }
    // Change Height of ListView
    ViewGroup.LayoutParams params = list.getLayoutParams();
    params.height = totalHeight
            + (list.getDividerHeight() * (shoutsList.size() - 1));
    list.setLayoutParams(params);
}

The problem is that I request new data from server when the user scroll down, but when I update listview height it auto scroll and request data automatically

Sayed
  • 255
  • 1
  • 3
  • 14
  • 1
    One question, why do you use ListView inside ScrollView? ListView is scrollable by itself... – miselking Feb 15 '15 at 15:24
  • 1
    Actualy, the listview is inside fragment which I include it inside scrollview. I don't want to edit this fragment – Sayed Feb 15 '15 at 15:31
  • 1
    [Dont put listview inside scrollview](http://stackoverflow.com/a/3496042/4428462) – Jonas Czech Feb 15 '15 at 15:48
  • So, what can I use as an alternative to listview? – Sayed Feb 15 '15 at 16:18
  • RecyclerView doesn't suffer the same problems as ListView. It allows wrap_content height and make sure the fixed height property is set to false. – Simon Feb 15 '15 at 18:38

0 Answers0