get Item Height of ListView - Android User Interface

Android examples for User Interface:ListView

Description

get Item 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 getItemHeightofListView(ListView listView, int items) {

        ListAdapter listAdapter = listView.getAdapter();
        int listviewElementsHeight = 0;

        for (int i = 0; i < items; i++) {
            View childView = listAdapter.getView(i, null, listView);
            childView.measure(View.MeasureSpec.makeMeasureSpec(0,
                    View.MeasureSpec.UNSPECIFIED), View.MeasureSpec
                    .makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            listviewElementsHeight += childView.getMeasuredHeight() + 3;
        }/*from w  ww .  ja v a  2 s . c  o m*/

        return listviewElementsHeight;

    }
}

Related Tutorials