get Total Height of ListView - Android User Interface

Android examples for User Interface:ListView

Description

get Total Height of ListView

Demo Code


//package com.java2s;

import android.view.View;

import android.widget.ListAdapter;
import android.widget.ListView;

public class Main {
    public static int getTotalHeightofListView(ListView listView) {

        ListAdapter mAdapter = listView.getAdapter();
        int totalHeight = 0;

        for (int i = 0; i < mAdapter.getCount(); i++) {
            View mView = mAdapter.getView(i, null, listView);

            mView.measure(View.MeasureSpec.makeMeasureSpec(0,
                    View.MeasureSpec.UNSPECIFIED), View.MeasureSpec
                    .makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));

            totalHeight += mView.getMeasuredHeight();
        }/*from  w  w  w.jav  a 2 s.  c om*/

        return totalHeight
                + (listView.getDividerHeight() * (mAdapter.getCount() - 1));
    }
}

Related Tutorials