Skip to content

Instantly share code, notes, and snippets.

View StevenByle's full-sized avatar

Steven Byle StevenByle

  • CapTech Consulting
  • Richmond, VA
View GitHub Profile
@StevenByle
StevenByle / ImageSelectorFragment.onOptionsItemSelected().java
Last active December 18, 2015 04:59
Android: Example showing layout dependent event handling. Taking different actions for phones and tablets.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.d(TAG, "onOptionsItemSelected");
switch (item.getItemId()) {
case R.id.menu_rotate:
Log.i(TAG, "onOptionsItemSelected: rotate menu item selected");
// This menu option is only provided to phone layouts, since
// tablet layouts show the image rotator at all times
@StevenByle
StevenByle / ImageSelectorFragment.onImageSelected().java
Last active March 24, 2019 07:34
Android: Example Fragment communication via interfaces with parents, and informing children Fragments of updates depending on their state.
@Override
public void onImageSelected(ImageItem imageItem, int position) {
// Only inform the other fragments if the selected position is new
if (mCurImagePosition != position) {
Log.d(TAG, "onImageSelected: title = " + imageItem.getTitle() + " position = " + position);
// Keep track of the selected image
mCurImageResourceId = imageItem.getImageResId();
@StevenByle
StevenByle / (layout) activity_main.xml
Last active April 9, 2021 03:58
Android: Loading Fragments dynamically at runtime depending on layout provided for the device configuration.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/activity_main_root_container">
<FrameLayout
android:id="@+id/activity_main_image_selector_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>