List of usage examples for android.widget GridView setAdapter
@Override public void setAdapter(ListAdapter adapter)
From source file:com.greendev.image.ImageGridFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.image_grid_fragment, container, false); final GridView mGridView = (GridView) v.findViewById(R.id.gridView); mGridView.setAdapter(mAdapter); mGridView.setOnItemClickListener(this); mGridView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override//w ww . j a va 2 s . c o m public void onScrollStateChanged(AbsListView absListView, int scrollState) { // Pause fetcher to ensure smoother scrolling when flinging if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) { mImageFetcher.setPauseWork(true); } else { mImageFetcher.setPauseWork(false); } } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }); // This listener is used to get the final width of the GridView and then // calculate the // number of columns and the width of each column. The width of each // column is variable // as the GridView has stretchMode=columnWidth. The column width is used // to set the height // of each view so we get nice square thumbnails. mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (mAdapter.getNumColumns() == 0) { final int numColumns = (int) Math .floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing)); if (numColumns > 0) { final int columnWidth = (mGridView.getWidth() / numColumns) - mImageThumbSpacing; mAdapter.setNumColumns(numColumns); mAdapter.setItemHeight(columnWidth); if (BuildConfig.DEBUG) { Log.d(TAG, "onCreateView - numColumns set to " + numColumns); } } } } }); return v; }
From source file:ca.etsmtl.applets.etsmobile.ScheduleWeekActivity.java
@SuppressWarnings("deprecation") @Override//from www .ja v a2 s. c o m public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.calendar_view_week); creds = new UserCredentials(PreferenceManager.getDefaultSharedPreferences(this)); TestFlight.passCheckpoint(this.getClass().getName()); // get data async handler = new CalendarTaskHandlerWeek(this); new CalendarTaskWeek(handler).execute(creds); // getCalendarICS(); // set the navigation bar navBar = (NavBar) findViewById(R.id.navBar1); navBar.setTitle(R.drawable.navbar_horaire_title); // set the gridview containing the day names final String[] day_names = getResources().getStringArray(R.array.day_names_5_days_week); final GridView grid = (GridView) findViewById(R.id.gridDayNames); grid.setAdapter(new ArrayAdapter<String>(this, R.layout.day_name, day_names)); // set next and previous buttons final ImageButton btn_previous = (ImageButton) findViewById(R.id.btn_previous); final ImageButton btn_next = (ImageButton) findViewById(R.id.btn_next); btn_previous.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { currentCalendar.previousWeek(); } }); btn_next.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { currentCalendar.nextWeek(); } }); // set the calendar view currentGridView = (NumGridViewWeek) findViewById(R.id.calendar_view); currentGridView.setOnCellTouchListener(mNumGridViewWeek_OnCellTouchListener); // assignation des session dja en mmoire currentGridView.setSessions(ETSMobileApp.getInstance().getSessionsFromPrefs()); // Affiche le mois courant final CalendarTextView txtcalendar_title = (CalendarTextView) findViewById(R.id.calendar_title); // initialisation des observers currentCalendar = new CurrentCalendar(); currentCalendar.addObserver(currentGridView); currentCalendar.addObserver(txtcalendar_title); // set DatePicker // ScheduleWeekActivity.this, 0, mDateSetListener, i, j, k); txtcalendar_title.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new DatePickerFragment(new WeakReference<ScheduleWeekActivity>(ScheduleWeekActivity.this)) .show(getSupportFragmentManager(), ""); } }); // currentCalendar.addObserver(datePickerDialog); currentCalendar.setChanged(); currentCalendar.notifyObservers(currentCalendar.getCalendar()); lst_cours = (CalendarEventsListView) findViewById(R.id.lst_cours); Log.v("ScheduleActivity", "ScheduleActivity: lst_cours=" + lst_cours); if (currentGridView != null) { if (currentGridView.getCurrentCell() != null) { Log.v("ScheduleWeekActivity", "ScheduleWeekActivity: onCreate: currentGridView.getCurrentCell()!=null"); currentGridView.getCurrentCell().addObserver(lst_cours); currentGridView.getCurrentCell().setChanged(); currentGridView.getCurrentCell().notifyObservers(); } } navBar.setRightButtonText(R.string.Ajourdhui); navBar.showRightButton(); navBar.setRightButtonAction(new View.OnClickListener() { @Override public void onClick(final View v) { if (currentGridView.getCurrentCell() != null) { currentGridView.getCurrentCell().deleteObservers(); currentGridView.setCurrentCell(null); } currentCalendar.setToday(); currentCalendar.setChanged(); if (currentGridView.getCurrentCell() != null) { currentGridView.getCurrentCell().addObserver(lst_cours); currentGridView.getCurrentCell().setChanged(); currentGridView.getCurrentCell().notifyObservers(); } else { lst_cours = (CalendarEventsListView) findViewById(R.id.lst_cours); lst_cours.resetAdaper(); } } }); }
From source file:io.valuesfeng.picker.control.PictureCollection.java
public void onCreate(@NonNull FragmentActivity context, @NonNull GridView gridView, SelectedUriCollection mCollection, SelectionSpec selectionSpec) { mContext = new WeakReference<Context>(context); mLoaderManager = context.getSupportLoaderManager(); this.selectionSpec = selectionSpec; albumPhotoAdapter = new PictureAdapter(context, null, mCollection); mCollection.getEngine().scrolling(gridView); gridView.setAdapter(albumPhotoAdapter); }
From source file:com.android.gpstest.GpsSatelliteFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRes = getResources();/*from w w w .j ava2 s . c o m*/ View v = inflater.inflate(R.layout.gps_satellite, container, false); mFlagUsa = ContextCompat.getDrawable(getActivity(), R.drawable.ic_flag_usa); mFlagRussia = ContextCompat.getDrawable(getActivity(), R.drawable.ic_flag_russia); mFlagJapan = ContextCompat.getDrawable(getActivity(), R.drawable.ic_flag_japan); mFlagChina = ContextCompat.getDrawable(getActivity(), R.drawable.ic_flag_china); mFlagGalileo = ContextCompat.getDrawable(getActivity(), R.drawable.ic_flag_galileo); GridView gridView = (GridView) v.findViewById(R.id.sv_grid); mAdapter = new SvGridAdapter(getActivity()); gridView.setAdapter(mAdapter); gridView.setFocusable(false); gridView.setFocusableInTouchMode(false); GpsTestActivity.getInstance().addListener(this); return v; }
From source file:com.brkc.traffic.ui.image.ImageGridFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.image_grid_fragment, container, false); final GridView mGridView = (GridView) v.findViewById(R.id.gridView); mGridView.setAdapter(mAdapter); mGridView.setOnItemClickListener(this); mGridView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override/* www . j a v a 2 s . co m*/ public void onScrollStateChanged(AbsListView absListView, int scrollState) { // Pause fetcher to ensure smoother scrolling when flinging if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) { // Before Honeycomb pause image loading on scroll to help with performance if (!Utils.hasHoneycomb()) { mImageFetcher.setPauseWork(true); } } else { mImageFetcher.setPauseWork(false); } } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }); // This listener is used to get the final width of the GridView and then calculate the // number of columns and the width of each column. The width of each column is variable // as the GridView has stretchMode=columnWidth. The column width is used to set the height // of each view so we get nice square thumbnails. mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @TargetApi(VERSION_CODES.JELLY_BEAN) @Override public void onGlobalLayout() { if (mAdapter.getNumColumns() == 0) { int test = mGridView.getWidth() / (mImageThumbWidth + mImageThumbSpacing); final int numColumns = (int) Math.floor(test); if (numColumns > 0) { int columnWidth = (mGridView.getWidth() / numColumns) - mImageThumbSpacing; final int columnHeight = columnWidth * mImageThumbHeightPercent / 100; mAdapter.setNumColumns(numColumns); mAdapter.setItemHeight(columnHeight); Log.d(TAG, "onCreateView - numColumns set to " + numColumns); if (Utils.hasJellyBean()) { mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } else { mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } } } } }); return v; }
From source file:com.concavenp.nanodegree.popularmoviesimproved.MovieListingFragment.java
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Set the layout for this fragment View view = inflater.inflate(R.layout.fragment_movieitem_grid, container, false); mFlipper = view.findViewById(R.id.movies_ViewFlipper); ////////////////////////////////////////// // view 1 of 2 in the flipper - the favorite movies ////////////////////////////////////////// // Create the adapter to link data from the DB to our specified item (result_item) mFavoritesAdapter = new SimpleCursorAdapter(getActivity(), R.layout.favorites_item, null, FROM, TO, 0); VIEW_BINDER.setListener(mListener);/*w w w . ja v a 2s.c om*/ mFavoritesAdapter.setViewBinder(VIEW_BINDER); GridView gridView = mFlipper.findViewById(R.id.main_favorite_movies_GridView); // Set the adapter gridView.setAdapter(mFavoritesAdapter); ////////////////////////////////////////// // view 2 of 2 in the flipper - the popular/voted movies ////////////////////////////////////////// RecyclerView recyclerView = mFlipper.findViewById(R.id.main_Movies_GridView); mAdapter = new MovieAdapter(mListener); recyclerView.setAdapter(mAdapter); GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), getResources().getInteger(R.integer.number_of_columns)); recyclerView.setLayoutManager(gridLayoutManager); mScrollListener = new EndlessRecyclerOnScrollListener(gridLayoutManager) { @Override public void onLoadMore(int current_page) { requestData(current_page); } }; recyclerView.addOnScrollListener(mScrollListener); // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView recyclerView.setHasFixedSize(true); ////////////////////////////////////////// return view; }
From source file:org.ecmdroid.activity.EEPROMActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.fetch: new FetchTask(this) { @Override/*w w w . ja v a 2 s.co m*/ protected void onPostExecute(Exception result) { super.onPostExecute(result); GridView gridview = (GridView) findViewById(R.id.eepromGrid); adapter = new EEPROMAdapter(EEPROMActivity.this, ecm.getEEPROM(), COLS); gridview.setAdapter(adapter); } }.start(); break; case R.id.burn: new BurnTask(this).start(); break; case R.id.save: new SaveTask(this, ecm.getEEPROM()).start(); break; case R.id.load: final StringBuilder result = new StringBuilder(); Dialog dlg = createLoadDialog(result); dlg.setOnDismissListener(new OnDismissListener() { public void onDismiss(DialogInterface dialog) { if (result.length() > 0) { if (ecm.isEepromRead() && ecm.getEEPROM().isTouched()) { AlertDialog.Builder builder = new AlertDialog.Builder(EEPROMActivity.this); builder.setTitle(R.string.load_eeprom).setMessage(R.string.overwrite_changes) .setCancelable(true).setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { loadEEPROM(new File(result.toString())); } }).show(); } else { loadEEPROM(new File(result.toString())); } } } }); dlg.show(); break; } return true; }
From source file:com.nike.plusgps.nikeplusgallery.MainActivity.java
/** * Handles the screen layouts based on the orientation. * The activity is not restarted when the orientation changes. *//*from w w w. ja v a 2 s . com*/ public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); // In Portrait mode the grid view is displayed if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { setContentView(R.layout.activity_main_port); GridView view = (GridView) findViewById(R.id.gridView); adapter = new FlickrFeedAdapter(getApplicationContext(), R.layout.single_elem_port, flickrFeedList, dbHelper, mMemoryCache); view.setAdapter(adapter); } else { // In Landscape mode the carousel view is displayed setContentView(R.layout.activity_main_land); carouselElement = (LinearLayout) findViewById(R.id.carousel); // Compute width of a carousel item based on screen width and initial item count final DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); final int imageWidth = (int) (displayMetrics.widthPixels / INITIAL_ITEMS_COUNT); // Fetches image url from SQLite cache ImageView imageItem; String imgURL; for (int i = 0; i < flickrFeedList.size(); ++i) { imageItem = new ImageView(this); imgURL = flickrFeedList.get(i).getMedia(); new DownloadImageTask(imageItem).execute(imgURL); imageItem.setLayoutParams(new LinearLayout.LayoutParams(imageWidth, imageWidth)); carouselElement.addView(imageItem); } } }
From source file:emojicon.EmojiconGridFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { GridView gridView = (GridView) view.findViewById(R.id.Emoji_GridView); Bundle bundle = getArguments();/*from w w w .jav a2s.c om*/ if (bundle == null) { mData = People.DATA; mUseSystemDefault = false; } else { mData = (Emojicon[]) getArguments().getParcelableArray(EMOJICONS_KEY); mUseSystemDefault = bundle.getBoolean(USE_SYSTEM_DEFAULT_KEY); } gridView.setAdapter(new EmojiAdapter(view.getContext(), mData, mUseSystemDefault)); gridView.setOnItemClickListener(this); }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display a grid of all installed apps + virtual apps. Allow user to launch * apps.//from ww w. jav a2 s.co m * * @param context * @param applications */ public static void displayAllApps(final Launcher context, final ArrayList<ApplicationInfo> applications) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.apps_grid); final GridView gridView = (GridView) dialog.findViewById(R.id.grid); gridView.setAdapter(new AllItemAdapter(context, getApplications(context, applications, false))); gridView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ItemInfo itemInfo = (ItemInfo) parent.getAdapter().getItem(position); itemInfo.invoke(context); context.showCover(false); dialog.dismiss(); if (itemInfo instanceof ApplicationInfo) { ApplicationInfo applicationInfo = (ApplicationInfo) itemInfo; RecentAppsTable.persistRecentApp(context, applicationInfo); } } }); gridView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> gridView, View view, int pos, long arg3) { ItemInfo itemInfo = (ItemInfo) gridView.getAdapter().getItem(pos); if (itemInfo instanceof ApplicationInfo) { Uri packageURI = Uri.parse("package:" + itemInfo.getIntent().getComponent().getPackageName()); Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI); context.startActivity(uninstallIntent); context.showCover(false); dialog.dismiss(); Analytics.logEvent(Analytics.UNINSTALL_APP); } return false; } }); gridView.setDrawingCacheEnabled(true); gridView.setOnKeyListener(onKeyListener); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ALL_APPS); }