Android ListView Size Get getListViewSize(ListView myListView)

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

Description

get List View Size

Declaration

public static void getListViewSize(ListView myListView) 

Method Source Code

//package com.java2s;

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 myListAdapter = myListView.getAdapter();
        if (myListAdapter == null) {
            //do nothing return null
            return;
        }/*from   ww  w.  jav  a 2  s .  c  o  m*/
        //set listAdapter in loop for getting final size
        int totalHeight = 15;
        for (int size = 0; size < myListAdapter.getCount(); size++) {
            View listItem = myListAdapter.getView(size, null, myListView);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }
        //setting listview item in adapter
        ViewGroup.LayoutParams params = myListView.getLayoutParams();
        params.height = totalHeight
                + (myListView.getDividerHeight() * (myListAdapter
                        .getCount() - 1));
        myListView.setLayoutParams(params);
    }
}

Related

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