Here you can find the source of getListViewSize(ListView myListView)
public static void getListViewSize(ListView myListView)
//package com.java2s; //License from project: Apache License import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.ListAdapter; import android.widget.ListView; public class Main { public static void getListViewSize(ListView myListView) { ListAdapter adapter = myListView.getAdapter(); if (adapter == null) return; int totalHeight = 0; for (int size = 0; size < adapter.getCount(); size++) { View listItem = adapter.getView(size, null, myListView); listItem.measure(0, 0);// w ww. ja v a2 s . com totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = myListView.getLayoutParams(); params.height = totalHeight + (myListView.getDividerHeight() * (adapter.getCount() - 1)); myListView.setLayoutParams(params); Log.i("height of listItem:", String.valueOf(totalHeight)); } }