List of usage examples for android.widget GridView getAdapter
@Override
public ListAdapter getAdapter()
From source file:Main.java
public static void setGridViewSize(GridView grid) { ListAdapter myListAdapter = grid.getAdapter(); if (myListAdapter == null) { //do nothing return null return;//from ww w .ja v a2 s . c o m } //set listAdapter in loop for getting final size int desiredWidth = View.MeasureSpec.makeMeasureSpec(grid.getWidth() / grid.getNumColumns(), View.MeasureSpec.AT_MOST); int totalHeight = 0; View view = null; for (int i = 0; i < ((myListAdapter.getCount() / grid.getNumColumns()) + myListAdapter.getCount() % grid.getNumColumns()); i++) { view = myListAdapter.getView(i, view, grid); if (i == 0) { view.setLayoutParams(new GridView.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT)); } view.measure(desiredWidth, View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); totalHeight += view.getMeasuredHeight(); } //setting listview item in adapter ViewGroup.LayoutParams params = grid.getLayoutParams(); params.height = totalHeight + (grid.getHorizontalSpacing() * (((myListAdapter.getCount() - 1) / grid.getNumColumns()) + (myListAdapter.getCount() % grid.getNumColumns()))); grid.setLayoutParams(params); }
From source file:Main.java
public static void getListViewSize(GridView myListView) { ListAdapter myListAdapter = myListView.getAdapter(); if (myListAdapter == null) { //do nothing return null return;//from w w w .j av a 2s . c om } //set listAdapter in loop for getting final size int totalHeight = 0; int listval = myListAdapter.getCount(); if (listval % 3 == 0) { listval = myListAdapter.getCount() / 3; } else { listval = myListAdapter.getCount() / 3 + 1; } for (int size = 0; size < listval; size++) { View listItem = myListAdapter.getView(size, null, myListView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } System.out.println("Height " + totalHeight + " " + myListAdapter.getCount()); //setting listview item in adapter ViewGroup.LayoutParams params = myListView.getLayoutParams(); params.height = totalHeight + ((myListView.getVerticalSpacing() / 3) * (myListAdapter.getCount() - 1)); myListView.setLayoutParams(params); // print height of adapter on log Log.i("height of listItem:", String.valueOf(totalHeight)); }
From source file:com.laevatein.internal.ui.helper.SelectedGridViewHelper.java
public static void tearDownGridView(Fragment fragment) { GridView gridView = (GridView) fragment.getView().findViewById(R.id.l_grid_photo); SelectedPhotoAdapter adapter = (SelectedPhotoAdapter) gridView.getAdapter(); adapter.unregisterCheckStateListener(); }
From source file:com.laevatein.internal.ui.helper.PhotoGridViewHelper.java
public static void setCursor(Fragment fragment, Cursor cursor) { GridView gridView = (GridView) fragment.getView().findViewById(R.id.l_grid_photo); CursorAdapter adapter = (CursorAdapter) gridView.getAdapter(); adapter.swapCursor(cursor);/*from w w w . ja va 2s . co m*/ }
From source file:com.laevatein.internal.ui.helper.PhotoGridViewHelper.java
public static void refreshView(Fragment fragment) { GridView gridView = (GridView) fragment.getView().findViewById(R.id.l_grid_photo); CursorAdapter adapter = (CursorAdapter) gridView.getAdapter(); adapter.notifyDataSetChanged();/*from w w w. j a v a2s . co m*/ }
From source file:com.laevatein.internal.ui.helper.PhotoGridViewHelper.java
public static void tearDownGridView(Fragment fragment) { GridView gridView = (GridView) fragment.getView().findViewById(R.id.l_grid_photo); AlbumPhotoAdapter adapter = (AlbumPhotoAdapter) gridView.getAdapter(); adapter.unregisterCheckStateListener(); }
From source file:com.optimusinfo.elasticpath.cortex.common.Utils.java
/** * This methods sets the gridview height * /* ww w . ja va 2s . c om*/ * @param gridView */ public static void setSingleCoulmnGridViewHeightBasedOnChildren(GridView gridView) { ViewGroup.LayoutParams params = gridView.getLayoutParams(); int size = gridView.getAdapter().getCount(); int dynamicHeight = Utils.getTotalHeightofListView(gridView); params.height = (dynamicHeight) + (dynamicHeight / size); gridView.setLayoutParams(params); gridView.requestLayout(); }
From source file:com.optimusinfo.elasticpath.cortex.common.Utils.java
/** * This methods sets the gridview height * //from w ww .j a v a 2s. c om * @param gridView */ public static void setGridViewHeightBasedOnChildren(GridView gridView, int columncount) { ViewGroup.LayoutParams params = gridView.getLayoutParams(); int size = gridView.getAdapter().getCount(); int dynamicHeight = Utils.getTotalHeightofListView(gridView); if (size % columncount == 0) { params.height = (dynamicHeight / columncount) + 25; } else { params.height = (dynamicHeight / columncount) + (dynamicHeight / size); } gridView.setLayoutParams(params); gridView.requestLayout(); }
From source file:util.Utils.java
/** * gridview//from w ww .ja v a2 s .c o m * * @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:org.bwgz.quotation.fragment.SubjectFragment.java
private void updateQuotations(Cursor cursor) { Log.d(TAG, String.format("updateQuotations - cursor: %s (%d)", cursor, cursor.getCount())); if (cursor.getCount() != 0) { GridView gridView = viewHolder.quotation_grid; if (gridView.getAdapter() instanceof QuotationPicksCursorAdapter) { QuotationPicksCursorAdapter adapter = (QuotationPicksCursorAdapter) gridView.getAdapter(); adapter.swapCursor(cursor);/* w w w . j a v a 2 s .c o m*/ } else { QuotationPicksCursorAdapter adapter = new QuotationPicksCursorAdapter(getView().getContext(), cursor, R.layout.quotation_pick_view, getImageLoader()); gridView.setAdapter(adapter); } } }