Example usage for android.widget ListAdapter getView

List of usage examples for android.widget ListAdapter getView

Introduction

In this page you can find the example usage for android.widget ListAdapter getView.

Prototype

View getView(int position, View convertView, ViewGroup parent);

Source Link

Document

Get a View that displays the data at the specified position in the data set.

Usage

From source file:Main.java

public static View getViewInList(ListView list, int index) {
    ListAdapter adapter = list.getAdapter();
    return adapter.getView(index, null, list);
}

From source file:Main.java

public static void updateListViewHeight(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();
        //HelperMethods.log("HEIGHT" + i, String.valueOf(totalHeight));

    }//ww  w.  ja v  a2  s.co m

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (mAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}

From source file:Main.java

public static int getTotalHeightofListView(ListView listView) {
    ListAdapter mAdapter = listView.getAdapter();
    if (mAdapter == null) {
        return 0;
    }//  w  w w  .java2s .  c o m
    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));
        //mView.measure(0, 0);
        totalHeight += mView.getMeasuredHeight();
        Log.w("HEIGHT" + i, String.valueOf(totalHeight));
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (mAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
    return params.height;
}

From source file:Main.java

public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return;//w ww.  ja  v  a  2s . c  o  m
    }
    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)) + 40;
    listView.setLayoutParams(params);
}

From source file:Main.java

public static void setListViewHeight(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return;//from   w w w.  java2s. c o m
    }
    int totalHeight = 0;
    for (int i = 0, len = listAdapter.getCount(); i < len; i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
}

From source file:Main.java

public static void setListViewHeight(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return;/*  w w w .ja v a2s  . com*/
    }
    int totalHeight = 0;
    for (int i = 0, len = listAdapter.getCount(); i < len; i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
}

From source file:Main.java

public static int setListViewHeight(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return 0;
    }//from  w  w w.  j  av a  2 s.  co  m
    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        if (listItem != null) {
            listItem.measure(0, 0);
            //                CommonUtils.LOGV("samton", "listItem Height === " + listItem.getMeasuredHeight());
            totalHeight += listItem.getMeasuredHeight();
        }
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    // ((MarginLayoutParams) params).setMargins(10, 10, 10, 10);
    listView.setLayoutParams(params);
    //        CommonUtils.LOGV("samton", "totalHeight Height === " +totalHeight
    //        );
    return totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
}

From source file:Main.java

/**
 * scollow -> listview hegiht//from   w  w w  .  j  a v  a  2 s.co m
 *
 * @param listView
 */
public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return;
    }
    int totalHeight = 0;
    for (int i = 0, len = listAdapter.getCount(); i < len; i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
        totalHeight += listItem.getMeasuredHeight();
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
}

From source file:Main.java

public static int setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return 0;
    }/*ww w .  j a  v  a2 s  .  co m*/

    int totalHeight = 0;
    for (int i = 0, count = listAdapter.getCount(); i < count; i++) {
        View item = listAdapter.getView(i, null, listView);
        item.measure(0, 0);
        totalHeight += item.getMeasuredHeight();
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    return params.height;
}

From source file:Main.java

/**
 * get AbsListView height according to every children
 * /*from w  w  w  .  j a v  a  2  s  .co m*/
 * @param view
 * @return
 */
public static int getAbsListViewHeightBasedOnChildren(AbsListView view) {
    ListAdapter adapter;
    if (view == null || (adapter = view.getAdapter()) == null) {
        return 0;
    }

    int height = 0;
    for (int i = 0; i < adapter.getCount(); i++) {
        View item = adapter.getView(i, null, view);
        if (item instanceof ViewGroup) {
            item.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        }
        item.measure(0, 0);
        height += item.getMeasuredHeight();
    }
    height += view.getPaddingTop() + view.getPaddingBottom();
    return height;
}