List of usage examples for android.widget ListAdapter getCount
int getCount();
From source file:com.kiwiteam.nomiddleman.TourPageActivity.java
/** * Makes listview items fill the list view on page to allow all list items to appear on page * @param listView/* w ww . ja v a2s. c om*/ */ public static void setListViewHeightBasedOnChildren(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, 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:com.android.argb.edhlc.Utils.java
public static void justifyListViewHeightBasedOnChildren(ListView listView) { ListAdapter adapter = listView.getAdapter(); if (adapter == null) return;//from w w w . j a va 2 s.com int totalHeight = 0; for (int i = 0; i < adapter.getCount(); i++) { View listItem = adapter.getView(i, null, listView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams par = listView.getLayoutParams(); par.height = totalHeight + (listView.getDividerHeight() * (adapter.getCount() - 1)); listView.setLayoutParams(par); listView.requestLayout(); }
From source file:com.lgallardo.qbittorrentclient.TorrentDetailsFragment.java
/** * *//from w w w. ja v a 2s.c om * Method for Setting the Height of the ListView dynamically. Hack to fix * the issue of not showing all the items of the ListView when placed inside * a ScrollView * ** */ public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) return; int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED); int totalHeight = 0; View view = null; for (int i = 0; i < listAdapter.getCount(); i++) { long numOfLines = 1; view = listAdapter.getView(i, view, listView); if (i == 0) { view.setLayoutParams(new LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT)); } view.measure(desiredWidth, MeasureSpec.UNSPECIFIED); TextView file = (TextView) view.findViewById(R.id.file); TextView percentage = (TextView) view.findViewById(R.id.percentage); ProgressBar progressBar1 = (ProgressBar) view.findViewById(R.id.progressBar1); if (view.getMeasuredWidth() > desiredWidth) { double viewWidthLong = Double.valueOf(view.getMeasuredWidth()); double desiredWidthLong = Double.valueOf(desiredWidth); numOfLines = Math.round(viewWidthLong / desiredWidthLong) + 1; totalHeight += (file.getMeasuredHeight() * numOfLines) + percentage.getMeasuredHeight() + progressBar1.getMeasuredHeight(); } else { totalHeight += view.getMeasuredHeight(); } } LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); listView.requestLayout(); }
From source file:com.example.awesomedogs.ui.MainActivityTest.java
public void testAssertDogsWereLoaded() { // List should show all dogs in the data class ListView listView = getListView(); ListAdapter adapter = listView.getAdapter(); assertNotNull(adapter);//from w w w . j av a2 s . c om assertEquals(DoggyData.getDogs().size(), adapter.getCount()); }
From source file:util.Utils.java
/** * gridview/*w w w . j a va2 s . c om*/ * * @param listView */ public static void setListViewHeightBasedOnChildren(GridView listView) { // ?listviewadapter ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { return; } // int col = listView.getNumColumns(); int totalHeight = 0; // i?4listAdapter.getCount()?4 item // listAdapter.getCount()?8 for (int i = 0; i < listAdapter.getCount(); i += col) { // ?listview?item View listItem = listAdapter.getView(i, null, listView); listItem.measure(0, 0); // ?item totalHeight += listItem.getMeasuredHeight(); } totalHeight += listView.getVerticalSpacing(); // ?listview? ViewGroup.LayoutParams params = listView.getLayoutParams(); // params.height = totalHeight; // margin // ((ViewGroup.MarginLayoutParams) params).setMargins(10, 10, 10, 10); // ? listView.setLayoutParams(params); }
From source file:com.nadmm.airports.ListFragmentBase.java
public void setAdapter(ListAdapter adapter) { mListView.setAdapter(adapter);// ww w . j a va2 s .co m int count = adapter == null ? 0 : adapter.getCount(); setListShown(count > 0); if (mListViewState != null) { mListView.onRestoreInstanceState(mListViewState); mListViewState = null; } setFragmentContentShown(true); }
From source file:net.illusor.swipeplayer.activities.SwipeActivityTest.java
@SmallTest public void testInitialBrowserState() throws Exception { View folderBrowserView = this.viewPager.getChildAt(1); DropDown dropDown = (DropDown) folderBrowserView.findViewById(R.id.id_fb_nav_history); assertNotNull("FolderBrowser dropdown is null", dropDown); SpinnerAdapter spinnerAdapter = dropDown.getAdapter(); assertNotNull("FolderBrowser dropdown adapter is null", spinnerAdapter); assertEquals("FolderBrowser dropdown adapter should initially contain 1 item", 1, spinnerAdapter.getCount());// w ww .ja v a 2s . c o m ListView listView = (ListView) folderBrowserView.findViewById(R.id.id_fb_audio_files); assertNotNull("FolderBrowser list is null", listView); ListAdapter listAdapter = listView.getAdapter(); assertNotNull("FolderBrowser list adapter is null", listAdapter); assertEquals("FolderBrowser list adapter should initially contain 1 item", 1, listAdapter.getCount()); }
From source file:org.mythdroid.fragments.RecListFragment.java
/** * Update which recording is selected/*from w w w. j av a2s. co m*/ */ public void updateSelection() { boolean newProgram = true; ListAdapter adapter = lv.getAdapter(); if (adapter == null) return; int maxIndex = adapter.getCount() - 1; if (maxIndex >= 0) activity.checkedIndex = Math.min(activity.checkedIndex, maxIndex); if (activity.checkedIndex > maxIndex) return; Program p = (Program) lv.getItemAtPosition(activity.checkedIndex); if (p == null) return; if (p.equals(Globals.curProg)) newProgram = false; Globals.curProg = p; lv.setSelection(activity.checkedIndex >= 0 ? activity.checkedIndex : activity.visibleIndex); if (!dualPane) return; lv.setItemChecked(activity.checkedIndex, true); // Do we need to add / replace the fragment in the details view slot? Fragment df = getFragmentManager().findFragmentById(R.id.recdetails); if (df == null || newProgram || (df.getClass().equals(RecDetailFragment.class) && (((RecDetailFragment) df).getProg() == null || !df.isVisible()))) showDetails(); }
From source file:com.bamobile.fdtks.util.Tools.java
public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) return;//w w w . ja v a 2s . co 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, 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() - 1)); listView.setLayoutParams(params); listView.requestLayout(); }
From source file:net.potterpcs.recipebook.RecipeListFragment.java
long[] getItemIds() { ListAdapter adapter = getListAdapter(); long[] ids = new long[adapter.getCount()]; for (int i = 0; i < ids.length; i++) { ids[i] = adapter.getItemId(i);/*from w w w . ja v a 2s .c om*/ } return ids; }