List of usage examples for android.widget ListAdapter getCount
int getCount();
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)); }/*from w ww .ja va 2 s . c o 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 void getListViewSize(ListView listView, Context context) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null || listAdapter.getCount() < 2) { // pre-condition return;// w ww . ja v a 2s . c om } WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); int totalHeight = 0; int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(size.x, View.MeasureSpec.AT_MOST); int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.AT_MOST); for (int i = 0; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, null, listView); listItem.measure(desiredWidth, listItem.getHeight()); totalHeight += listItem.getMeasuredHeight(); } totalHeight += listView.getPaddingTop() + listView.getPaddingBottom(); totalHeight += (listView.getDividerHeight() * (listAdapter.getCount() + 1)); ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight; listView.setLayoutParams(params); listView.requestLayout(); }
From source file:Main.java
/** * get ListView height according to every children * //from w w w. j a v a 2s . c o m * @param view * @return */ public static int getListViewHeightBasedOnChildren(ListView view) { int height = getAbsListViewHeightBasedOnChildren(view); ListAdapter adapter; int adapterCount; if (view != null && (adapter = view.getAdapter()) != null && (adapterCount = adapter.getCount()) > 0) { height += view.getDividerHeight() * (adapterCount - 1); } return height; }
From source file:Main.java
public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { return;//from www.j a v a 2 s .co 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 ww . j a v a2s . c om } 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 . j a v a 2 s . 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 int getTotalHeightofListView(ListView listView) { ListAdapter mAdapter = listView.getAdapter(); if (mAdapter == null) { return 0; }/*w w w . j a v a 2s. com*/ 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
/** * scollow -> listview hegiht//w w w .ja v a 2 s .c o 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; }/*from w w w. ja v a2 s .c o 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
public static int setListViewHeight(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { return 0; }//from www . j a v a2 s.c om 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)); }