List of usage examples for android.widget GridView setAdapter
@Override public void setAdapter(ListAdapter adapter)
From source file:com.laer.easycast.VideoPane.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = new View(getActivity()); root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); root.setBackgroundColor(Color.WHITE); root = inflater.inflate(R.layout.imagepane, container, false); setHasOptionsMenu(true);//from w w w . j av a2 s . c o m myViewGroup = container; cursor = getActivity().getContentResolver().query(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, projection, // Which columns to return null, // Return all rows null, MediaStore.Video.Thumbnails.VIDEO_ID); // Get the column index of the Thumbnails Image ID columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Thumbnails._ID); GridView gridView = (GridView) root.findViewById(R.id.gridView1); gridView.setAdapter(new ImageAdapter(getActivity())); gridView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { String[] projection = { MediaStore.Video.Media.DATA }; try { cursor = getActivity().getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, // Which columns to return null, // Return all rows null, null); columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); } catch (SQLiteException e) { } cursor.moveToPosition(position); // Get image filename String imagePath = cursor.getString(columnIndex); // Bitmap image = BitmapFactory.decodeFile(imagePath); Log.i("VideoPath=", imagePath); Log.d(TAG, "Video decoded"); // videoRaw(image,NONE); // Use this path to do further processing, i.e. full screen // display } }); return root; }
From source file:com.drivehype.www.drivehype.ui.ImageGridFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { android.util.Log.d("extraCount", "on create view of IGF"); 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//from ww w .j a v a 2 s.c om 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) { 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); } if (Utils.hasJellyBean()) { mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } else { mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } } } } }); return v; }
From source file:ca.etsmtl.applets.etsmobile.ScheduleActivity.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.calendar_view); TestFlight.passCheckpoint(this.getClass().getName()); creds = new UserCredentials(PreferenceManager.getDefaultSharedPreferences(this)); // get data async handler = new CalendarTaskHandler(this); new CalendarTaskMonth(handler).execute(creds); // 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); 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//from w w w . ja v a2 s . com public void onClick(final View v) { currentCalendar.previousMonth(); } }); btn_next.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { currentCalendar.nextMonth(); } }); // set the calendar view currentGridView = (NumGridView) findViewById(R.id.calendar_view); currentGridView.setOnCellTouchListener(mNumGridView_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); txtcalendar_title.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new DatePickerFragment(new WeakReference<ScheduleActivity>(ScheduleActivity.this)) .show(getSupportFragmentManager(), "date-frag-tag"); } }); currentCalendar.setChanged(); currentCalendar.notifyObservers(currentCalendar.getCalendar()); Log.v("ScheduleActivity", "ScheduleActivity: lst_cours=" + lst_cours); lst_cours = (CalendarEventsListView) findViewById(R.id.lst_cours); 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) { currentGridView.getCurrentCell().deleteObservers(); currentGridView.setCurrentCell(null); currentCalendar.setToday(); currentGridView.getCurrentCell().addObserver(lst_cours); currentGridView.getCurrentCell().setChanged(); currentGridView.getCurrentCell().notifyObservers(); } }); }
From source file:com.volley.demo.SimpleCacheFragment.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/*from w w w. ja v a2 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) { // Before Honeycomb pause image loading on scroll to help // with performance if (!Utils.hasHoneycomb()) { mImageLoader.stopProcessingQueue(); } } else { mImageLoader.startProcessingQueue(); } } @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(Build.VERSION_CODES.JELLY_BEAN) @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); } if (Utils.hasJellyBean()) { mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } else { mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } } } } }); return v; }
From source file:mk.apps.soundblog.fragment.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//ww w . ja v a 2 s. com 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) { // final int numColumns = (int) Math.floor( // mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing)); final int numColumns = 2; 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); } if (Utils.hasJellyBean()) { mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } else { mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } } } } }); return v; }
From source file:com.njlabs.amrita.aid.landing.Landing.java
private void setupGrid() { GridView gridView = (GridView) findViewById(R.id.landing_grid); gridView.setAdapter(new LandingAdapter(baseContext)); gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from w w w. j a va 2 s .c o m public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { String name = ((TextView) view.getTag(R.id.landing_text)).getText().toString(); switch (name) { case "About Amrita": // ABOUT AMRITA startActivity(new Intent(baseContext, Amrita.class)); break; case "Announcements": Snackbar.make(parentView, "Announcements is under construction", Snackbar.LENGTH_SHORT).show(); break; case "Academic Calender": // ACADEMIC CALENDER startActivity(new Intent(baseContext, Calender.class)); break; case "Amrita UMS Login": // AUMS startActivity(new Intent(baseContext, AumsActivity.class)); break; case "Train & Bus Timings": // TRAIN & BUS INFO final CharSequence[] transportationOptions = { "Trains from Coimbatore", "Trains from Palghat", "Trains to Coimbatore", "Trains to Palghat", "Buses from Coimbatore", "Buses to Coimbatore" }; AlertDialog.Builder transportationDialogBuilder = new AlertDialog.Builder(baseContext); transportationDialogBuilder.setTitle("View timings of ?"); transportationDialogBuilder.setItems(transportationOptions, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { // Showing Alert Message Intent trainBusOpen = new Intent(baseContext, TrainBusInfo.class); trainBusOpen.putExtra("type", transportationOptions[item]); startActivity(trainBusOpen); } }); AlertDialog transportationDialog = transportationDialogBuilder.create(); transportationDialog.show(); break; case "GPMS Login": // GPMS LOGIN startActivity(new Intent(baseContext, GpmsActivity.class)); break; case "Curriculum Info": // CURRICULUM INFO final CharSequence[] items_c = { "Aerospace Engineering", "Civil Engineering", "Chemical Engineering", "Computer Science Engineering", "Electrical & Electronics Engineering", "Electronics & Communication Engineering", "Electronics & Instrumentation Engineering", "Mechanical Engineering" }; AlertDialog.Builder departmentDialogBuilder = new AlertDialog.Builder(baseContext); departmentDialogBuilder.setTitle("Select your Department"); departmentDialogBuilder.setItems(items_c, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { // Showing Alert Message Intent curriculum_open = new Intent(baseContext, Curriculum.class); curriculum_open.putExtra("department", items_c[item]); startActivity(curriculum_open); } }); AlertDialog departmentDialog = departmentDialogBuilder.create(); departmentDialog.show(); break; case "News": // NEWS startActivity(new Intent(baseContext, NewsActivity.class)); break; default: Toast.makeText(baseContext, String.valueOf(i), Toast.LENGTH_SHORT).show(); } } }); }
From source file:org.ecmdroid.activity.EEPROMActivity.java
private void loadEEPROM(String id, File file) { try {/*from w w w . ja v a 2 s . c o m*/ FileInputStream in = new FileInputStream(file); EEPROM eeprom = EEPROM.load(this, ecm.getId(), id, in); if (ecm.isConnected() && !eeprom.getId().equals(ecm.getId())) { throw new IOException(getString(R.string.incompatible_version_disconnect_first, id)); } ecm.setEEPROM(eeprom); Toast.makeText(EEPROMActivity.this, R.string.eeprom_loaded_sucessfully, Toast.LENGTH_LONG).show(); GridView gridview = (GridView) findViewById(R.id.eepromGrid); adapter = new EEPROMAdapter(EEPROMActivity.this, ecm.getEEPROM(), COLS); gridview.setAdapter(adapter); } catch (IOException e) { Toast.makeText(EEPROMActivity.this, getString(R.string.unable_to_load_eeprom) + " " + e.getLocalizedMessage(), Toast.LENGTH_LONG) .show(); } }
From source file:com.fastbootmobile.encore.app.fragments.PlaylistListFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); // If mAdapter isn't null, we're in portrait with the draggable list view. if (mAdapter != null) { mRecyclerView = (RecyclerView) view.findViewById(R.id.rvPlaylists); mLayoutManager = new LinearLayoutManager(getContext()); // drag & drop manager mRecyclerViewDragDropManager = new RecyclerViewDragDropManager(); //adapter mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(mAdapter); // wrap for dragging final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator(); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); // additional decorations mRecyclerView.addItemDecoration( new SimpleListDividerDecorator(getResources().getDrawable(R.drawable.list_divider), true)); mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView); if (!mIsStandalone) { mRecyclerView.setPadding(0, 0, 0, 0); }/*from ww w . j a v a 2s . c o m*/ } else { // We're in landscape with the grid view GridView root = (GridView) view.findViewById(R.id.gvPlaylists); root.setAdapter(mGridAdapter); if (!mIsStandalone) { root.setPadding(0, 0, 0, 0); } // Setup the click listener root.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { MainActivity act = (MainActivity) getActivity(); PlaylistGridAdapter.ViewHolder tag = (PlaylistGridAdapter.ViewHolder) view.getTag(); Intent intent = PlaylistActivity.craftIntent(act, mGridAdapter.getItem(position), ((MaterialTransitionDrawable) tag.ivCover.getDrawable()).getFinalDrawable() .getBitmap()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ActivityOptions opt = ActivityOptions.makeSceneTransitionAnimation(getActivity(), tag.ivCover, "itemImage"); act.startActivity(intent, opt.toBundle()); } else { act.startActivity(intent); } } }); } }
From source file:com.fabioarias.ui.Search.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.p1: // BUSQUEDA POR CRITERIA ApiReader reader = new ApiReader(getActivity().getString(R.string.host), "searchByCriteria/" + searchField.getText(), "servers"); try {//from w w w. j a v a 2s .c o m categories = reader.getItems(); Log.e("CATEGORIAS", "LEYENDO CATEGORIAS"); if (categories != null) { Log.e("CATEGORIAS", "OK"); } else { Log.e("CATEGORIAS", "NOK "); } } catch (Exception e) { e.printStackTrace(); Log.e("CATEGORIAS", e.getMessage()); } GridView grid = (GridView) this.v.findViewById(R.id.grid_search); grid.setVisibility(View.VISIBLE); grid.setAdapter(new GridAdapter()); break; case R.id.p2: // SCANING BARCODE try { // Pdf417MobiSettings sett = new Pdf417MobiSettings(); // Set this to true to scan even barcode not compliant with // standards // For example, malformed PDF417 barcodes which were incorrectly // encoded // Use only if necessary because it slows down the recognition // process // sett.setUncertainScanning(true); // Set this to true to scan barcodes which don't have quiet zone // (white area) around it // Use only if necessary because it drastically slows down the // recognition process // sett.setNullQuietZoneAllowed(true); // set this to true to enable QR code scanning // sett.setQrCodeEnabled(true); // set this to true to prevent showing dialog after successful // scan // sett.setDontShowDialog(false); // sett.setAll1DBarcodesEnabled(true); // sett.setCode128Enabled(true); // sett.setCode39Enabled(true); // sett.setEan13Enabled(true); // sett.setEan8Enabled(true); // if license permits this, remove Pdf417.mobi logo overlay on // scan activity // if license forbids this, this option has no effect Log.i("SEARCH", ((MainActivity) getActivity()).getCart().toString()); Bundle b = new Bundle(); Intent intent = new Intent("com.fabioarias.SCAN"); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); intent.putExtra("SCAN_MODE", "PDF417_MODE"); intent.putExtra("SCAN_MODE", "ONE_D_MODE"); startActivityForResult(intent, 0); // sett.setRemoveOverlayEnabled(true); // Intent intent = new Intent((MainActivity)getActivity(), // Pdf417ScanActivity.class); // intent.putExtra(BaseBarcodeActivity.EXTRAS_SETTINGS, sett); // intent.putExtra("CART", // ((MainActivity)getActivity()).getCart().toString()); // // intent.putExtra(BaseBarcodeActivity.EXTRAS_LICENSE_KEY, // "1c61089106f282473fbe6a5238ec585f8ca0c29512b2dea3b7c17b8030c9813dc965ca8e70c8557347177515349e6e"); // Start Activity // startActivityForResult(intent, 0); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(this.getActivity().getApplicationContext(), "ERROR:" + e, 1).show(); } break; } }
From source file:org.ecmdroid.activity.EEPROMActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.eeprom);//www . j av a2 s . co m offsetHex = (TextView) findViewById(R.id.offsetHex); offsetDec = (TextView) findViewById(R.id.offsetDec); byteValHex = (TextView) findViewById(R.id.byteValHex); byteValDec = (TextView) findViewById(R.id.byteValDec); hiShortHex = (TextView) findViewById(R.id.hiShortHex); hiShortDec = (TextView) findViewById(R.id.hiShortDec); loShortHex = (TextView) findViewById(R.id.loShortHex); loShortDec = (TextView) findViewById(R.id.loShortDec); cellInfo = (TextView) findViewById(R.id.cellInfo); GridView gridview = (GridView) findViewById(R.id.eepromGrid); adapter = new EEPROMAdapter(this, ecm.getEEPROM(), COLS); gridview.setAdapter(adapter); // TODO: Chose a nice drawable for currently selected cell //gridview.setSelector(android.R.drawable.edit_text); gridview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int pos, long id) { if (pos % COLS != 0) { int offset = pos - (pos / COLS + 1); showCellInfo(offset); } } }); gridview.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int pos, long id) { if (pos % COLS != 0) { int offset = pos - (pos / COLS + 1); showCellInfo(offset); byte value = ecm.getEEPROM().getBytes()[offset]; CellEditorDialogFragment editor = CellEditorDialogFragment.newInstance(offset, value); editor.show(getSupportFragmentManager(), "EEPROMActivity"); } return false; } }); if (ACTION_BURN.equals(getIntent().getAction())) { SharedPreferences pm = PreferenceManager.getDefaultSharedPreferences(this); if (pm.getBoolean(Constants.PREFS_ENABLE_BURN, false)) { new BurnTask(this).start(); } else { Toast.makeText(EEPROMActivity.this, R.string.eeprom_burning_disabled_by_configuration, Toast.LENGTH_LONG).show(); } } }