Android ListView Size Get getListViewSize(ListView myListView)

Here you can find the source of getListViewSize(ListView myListView)

Description

get List View Size

License

Apache License

Declaration

public static void getListViewSize(ListView myListView) 

Method Source Code

//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));
    }
}

Related

  1. getListViewSize(ListView myListView)
  2. getAbsListViewHeight(AbsListView absListView, int lineNumber, int verticalSpace)
  3. getAbsListViewHeight(AbsListView absListView, int lineNumber, int verticalSpace)
  4. getListViewHeight(AbsListView absListView, int lineNumber, int verticalSpace)