title: How to calculate total row heights of listView in android?
body: <p>I used this code to get the total heights of listview row items but it did not returns the actual height. Here is the used code </p>
  
  <pre><code>public static void setListViewHeightBasedOnChildren(ListView listView) {
          ListAdapter listAdapter = listView.getAdapter(); 
          if (listAdapter == null) {
              // pre-condition
              return;
          }
  
          int totalHeight = 0;
          for (int i = 0; i &lt; listAdapter.getCount(); i++) {
              View listItem = listAdapter.getView(i, null, listView);
              listItem.measure(0, 0);
              totalHeight += listItem.getMeasuredHeight();
          }
  
          ViewGroup.LayoutParams params = listView.getLayoutParams();
          params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
          listView.setLayoutParams(params);
          listView.requestLayout();
      }
  </code></pre>
  
  <p>For example: I have a listview with 20 rows and each rows height is different from each others suppose that 200,300,500. When I use this above code, it did not returns actual height for me. Also I tried this answer : <a href="https://stackoverflow.com/questions/15039913/android-how-to-measure-total-height-of-listview">Android: How to measure total height of ListView</a> 
  But did not works. How can I get rid of this problem. Can anyone explain this solution?? </p>