Android Utililty Methods ListView Size Get

List of utility methods to do ListView Size Get

Description

The list of methods to do ListView Size Get are organized into topic(s).

Method

voidgetListViewSize(ListView myListView)
get List View Size
ListAdapter myListAdapter = myListView.getAdapter();
if (myListAdapter == null) {
    return;
int totalHeight = 15;
for (int size = 0; size < myListAdapter.getCount(); size++) {
    View listItem = myListAdapter.getView(size, null, myListView);
    listItem.measure(0, 0);
...
intgetAbsListViewHeight(AbsListView absListView, int lineNumber, int verticalSpace)
get Abs List View Height
int totalHeight = 0;
int w = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
int h = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
absListView.measure(w, h);
ListAdapter mListAdapter = absListView.getAdapter();
if (mListAdapter == null) {
    return totalHeight;
int count = mListAdapter.getCount();
if (absListView instanceof ListView) {
    for (int i = 0; i < count; i++) {
        View listItem = mListAdapter.getView(i, null, absListView);
        listItem.measure(w, h);
        totalHeight += listItem.getMeasuredHeight();
    if (count == 0) {
        totalHeight = verticalSpace;
    } else {
        totalHeight = totalHeight
                + (((ListView) absListView).getDividerHeight() * (count - 1));
} else if (absListView instanceof GridView) {
    int remain = count % lineNumber;
    if (remain > 0) {
        remain = 1;
    if (mListAdapter.getCount() == 0) {
        totalHeight = verticalSpace;
    } else {
        View listItem = mListAdapter.getView(0, null, absListView);
        listItem.measure(w, h);
        int line = count / lineNumber + remain;
        totalHeight = line * listItem.getMeasuredHeight()
                + (line - 1) * verticalSpace;
return totalHeight;
intgetAbsListViewHeight(AbsListView absListView, int lineNumber, int verticalSpace)
get Abs List View Height
int totalHeight = 0;
int w = View.MeasureSpec.makeMeasureSpec(0,
        View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(0,
        View.MeasureSpec.UNSPECIFIED);
absListView.measure(w, h);
ListAdapter mListAdapter = absListView.getAdapter();
if (mListAdapter == null) {
...
intgetListViewHeight(AbsListView absListView, int lineNumber, int verticalSpace)
get List View Height
int totalHeight = 0;
int w = View.MeasureSpec.makeMeasureSpec(0,
        View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(0,
        View.MeasureSpec.UNSPECIFIED);
absListView.measure(w, h);
ListAdapter mListAdapter = absListView.getAdapter();
if (mListAdapter == null) {
...
voidgetListViewSize(ListView myListView)
get List View Size
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);
    totalHeight += listItem.getMeasuredHeight();
...