3

Ok.. first of all, i know its very much discouraged to not put a listview in a scrollview, but this time it was out of my hands and i had no choice. Now going forward, My Listview items are not showing the last few items in the adapter when it reaches a certain amount. Not treally sure how to explain it but What i mean is as an example is, items from: Jan 1 - Aug 22, the listview stops at Aug 15, Jan 1 - Aug 17, it stops at Aug 10 Jan 1 - Mar 17, stops at Mar 15 and so on.

Not really sure what the problem is.. i am using a custom Listview like:

public static void setListViewHeight(ListView listview){
        ListAdapter listAdapter = listview.getAdapter();
        if(listAdapter == null) {
            return;
        }

        int totalHeight = 0;
       // int desiredWidth = MeasureSpec.makeMeasureSpec(listview.getWidth(), MeasureSpec.AT_MOST);
        for(int i = 0; i < listAdapter.getCount(); i++) {
            View listItem = listAdapter.getView(i, null, listview);
            //listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params = listview.getLayoutParams();
        params.height = totalHeight + (listview.getDividerHeight()*(listAdapter.getCount() - 1)) + totalHeight;
        listview.setLayoutParams(params);
        //listview.requestLayout();
    }

Anybody have any issue like the Listview not showing all the items?... Any idea how to solve this?.. Much appreciated in advance.

irobotxx
  • 5,963
  • 11
  • 62
  • 91
  • have you seen answer?? – Sanket Kachhela Aug 22 '13 at 17:38
  • Look on the bright side. Now you know why you should not put a list view inside a scroll view! I hope the person who decided that you should do it is paying you by the hour. [sorry for the flippant comment but this is a case of "Patient: Doctor, it hurts when I do this. Doctor: Don't do that." – Dale Wilson Aug 22 '13 at 18:59
  • @DaleWilson haha, yes i know, i tried to fight them with that but its rather difficult when they keep referring to iphone.. which is another matter i don't want to talk about. :) – irobotxx Aug 23 '13 at 09:56
  • @sparrow have you tried with link that i have given to you? and that is not of iPhone. – Sanket Kachhela Aug 23 '13 at 11:45

1 Answers1

8

try with

listview.setExpand(true);

You can put multiple listview inside scrollview. See this https://stackoverflow.com/a/18354096/942224

Community
  • 1
  • 1
Sanket Kachhela
  • 10,861
  • 8
  • 50
  • 75
  • 2
    Thanks! Works really well. Anyone should follow the link to understand what the answer here means. – irobotxx Aug 23 '13 at 13:08