List of usage examples for android.widget ListView getAdapter
@Override
public ListAdapter getAdapter()
From source file:com.google.cast.samples.games.gamedebugger.DebuggerFragment.java
public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { return;/*from w w w . j ava 2s . c om*/ } int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom(); for (int i = 0; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, null, listView); listItem.measure(View.MeasureSpec.UNSPECIFIED, View.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 View getItemFromListViewByPosition(final int pos, @NonNull final ListView listView) { final int firstListItemPosition = listView.getFirstVisiblePosition(); final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1; if (pos < firstListItemPosition || pos > lastListItemPosition) { return listView.getAdapter().getView(pos, null, listView); } else {//from ww w . j av a 2s. co m final int childIndex = pos - firstListItemPosition; return listView.getChildAt(childIndex); } }
From source file:com.poloure.simplerss.Utilities.java
static void setTitlesAndDrawerAndPage(Fragment fragment, int absolutePos) { String[] navTitles = s_resources.getStringArray(R.array.navigation_titles); if (null != fragment) { switchToFragment(fragment, false); }// ww w . jav a 2s . c o m ListView list = s_fragmentDrawer.m_listView; HeaderViewListAdapter headerAdapter = (HeaderViewListAdapter) list.getAdapter(); int headers = headerAdapter.getHeadersCount(); int listPosition = -10 == absolutePos ? s_viewPager.getCurrentItem() + headers : absolutePos; int viewPagerPos = -10 == absolutePos ? s_viewPager.getCurrentItem() : absolutePos - headers; // Check the drawer item. String title = PagerAdapterTags.s_tagList.get(0); String subTitle = null; int imageRes = R.drawable.ic_action_labels; if (s_fragmentFavourites.isVisible()) { listPosition = 0; title = navTitles[0]; imageRes = R.drawable.ic_action_important; } else if (s_fragmentManage.isVisible()) { listPosition = 1; title = navTitles[1]; imageRes = R.drawable.ic_action_storage; } else if (s_fragmentSettings.isVisible()) { listPosition = 2; title = navTitles[2]; imageRes = R.drawable.ic_action_settings; } else { ArrayAdapter<String[]> adapter = (ArrayAdapter<String[]>) headerAdapter.getWrappedAdapter(); if (null != adapter && 0 < adapter.getCount()) { String[] item = adapter.getItem(viewPagerPos); title = item[0]; int count = null == item[1] || item[1].isEmpty() ? 0 : Integer.parseInt(item[1]); String countString = s_resources.getQuantityString(R.plurals.actionbar_subtitle_unread, count, count); subTitle = 0 == count ? null : countString; } } s_actionBar.setTitle(title); s_actionBar.setSubtitle(subTitle); s_actionBar.setIcon(imageRes); list.setItemChecked(listPosition, true); // If we must change the view pager page. if (0 <= viewPagerPos) { // Switch the view pager page if different. if (s_viewPager.getCurrentItem() != viewPagerPos) { s_viewPager.setCurrentItem(viewPagerPos); } } }
From source file:com.bobomee.android.common.util.ScreenUtil.java
/** * http://stackoverflow.com/questions/12742343/android-get-screenshot-of-all-listview-items *//* ww w. ja v a 2 s. co m*/ public static Bitmap shotListView(ListView listview) { ListAdapter adapter = listview.getAdapter(); int itemscount = adapter.getCount(); int allitemsheight = 0; List<Bitmap> bmps = new ArrayList<Bitmap>(); for (int i = 0; i < itemscount; i++) { View childView = adapter.getView(i, null, listview); childView.measure(View.MeasureSpec.makeMeasureSpec(listview.getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); childView.layout(0, 0, childView.getMeasuredWidth(), childView.getMeasuredHeight()); childView.setDrawingCacheEnabled(true); childView.buildDrawingCache(); bmps.add(childView.getDrawingCache()); allitemsheight += childView.getMeasuredHeight(); } Bitmap bigbitmap = Bitmap.createBitmap(listview.getMeasuredWidth(), allitemsheight, Bitmap.Config.ARGB_8888); Canvas bigcanvas = new Canvas(bigbitmap); Paint paint = new Paint(); int iHeight = 0; for (int i = 0; i < bmps.size(); i++) { Bitmap bmp = bmps.get(i); bigcanvas.drawBitmap(bmp, 0, iHeight, paint); iHeight += bmp.getHeight(); bmp.recycle(); bmp = null; } return bigbitmap; }
From source file:net.mEmoZz.PopMovies.frags.DetailFragment.java
/** * Got this form here://from www .jav a 2 s. c om * http://stackoverflow.com/a/19311197/4043944 */ public static void fix(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) return; int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED); int totalHeight = 0; View view = null; for (int i = 0; i < listAdapter.getCount(); i++) { view = listAdapter.getView(i, view, listView); if (i == 0) view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT)); view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED); totalHeight += view.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); }
From source file:rta.ae.sharekni.Display_My_Vehicles.java
public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) return;/*from w ww . ja v a2 s. c o m*/ int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED); int totalHeight = 0; View view = null; for (int i = 0; i < listAdapter.getCount(); i++) { view = listAdapter.getView(i, view, listView); if (i == 0) view.setLayoutParams( new ViewGroup.LayoutParams(desiredWidth, RadioGroup.LayoutParams.WRAP_CONTENT)); view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED); totalHeight += view.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); listView.requestLayout(); }
From source file:com.optimusinfo.elasticpath.cortex.common.Utils.java
public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { // pre-condition return;/*from w ww.j a va 2 s . c om*/ } 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)); listView.setLayoutParams(params); listView.requestLayout(); }
From source file:com.kiwiteam.nomiddleman.LargeGroupActivity.java
public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) return;//from w w w .jav a 2 s .com int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED); int totalHeight = 0; View view = null; for (int i = 0; i < listAdapter.getCount(); i++) { view = listAdapter.getView(i, view, listView); if (i == 0) view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT)); view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED); totalHeight += view.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount())); listView.setLayoutParams(params); listView.requestLayout(); }
From source file:nl.mpcjanssen.simpletask.util.Util.java
public static ArrayList<String> getCheckedItems(ListView listView, boolean checked) { SparseBooleanArray checks = listView.getCheckedItemPositions(); ArrayList<String> items = new ArrayList<String>(); for (int i = 0; i < checks.size(); i++) { String item = (String) listView.getAdapter().getItem(checks.keyAt(i)); if (checks.valueAt(i) && checked) { items.add(item);//from ww w .ja v a2 s . c om } else if (!checks.valueAt(i) && !checked) { items.add(item); } } return items; }
From source file:com.nps.micro.view.TestsSectionFragment.java
public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { // pre-condition return;//from ww w.j a v a2 s.c o m } int totalHeight = 1; 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)); listView.setLayoutParams(params); listView.requestLayout(); }