Example usage for android.app Fragment setArguments

List of usage examples for android.app Fragment setArguments

Introduction

In this page you can find the example usage for android.app Fragment setArguments.

Prototype

public void setArguments(Bundle args) 

Source Link

Document

Supply the construction arguments for this fragment.

Usage

From source file:se.liu.tddd77.bilsensor.MainActivity.java

/**
 * Run every time an item in the list is clicked. 
 * If the application is run on a tablet, replace the current fragment with
 * the one associated with the index. Otherwise, start the activity
 * associated with the index. // w  w w . ja v a2  s  .  c  om
 */
@Override
public void onItemSelected(int index) {
    //      try {
    //         //Backend.getInstance().clearActiveOnScreen();
    //      } catch (BackendError e) {
    //         // TODO Auto-generated catch block
    //         e.printStackTrace();
    //      }
    if (mSplitScreen) {
        android.app.Fragment fragment = ElementList.getInstance().getElement(index).getFragment();
        if (fragment == getFragmentManager().findFragmentById(R.id.sensor_detail_container)) {
            Log.i("MainActivity", "onItemSelected: Old fragment");
            return;
        }

        Bundle arguments = new Bundle();
        arguments.putInt(SensorDetailFragment.ARG_ITEM_ID, index);
        fragment.setArguments(arguments);
        getFragmentManager().beginTransaction().replace(R.id.sensor_detail_container, fragment).commit();
        Log.i("MainActivity", "onItemSelected: Split screen");

    } else {
        Intent detailIntent = new Intent(this, SensorDetailActivity.class);
        detailIntent.putExtra(SensorDetailFragment.ARG_ITEM_ID, index);
        startActivity(detailIntent);
        Log.i("MainActivity", "onItemSelected: Not split screen");
    }
}

From source file:com.casin.activity.HomeDrawerActivity.java

private void selectItem(int position, String tag) {

    String[] arrayAllData = { "Select Game", "Profile", "Change Password", "My Winnings", "Create User",
            "Transfer Points", "Settings", "Signout", "Create Broker" };
    Bundle args = new Bundle();

    // update the main content by replacing fragments
    Fragment fragment = new ProfileFragment();

    if (tag.equalsIgnoreCase(arrayAllData[0])) {
        fragment = new HomeFragment();
    } else if (tag.equalsIgnoreCase(arrayAllData[1])) {
        fragment = new ProfileFragment();

    } else if (tag.equalsIgnoreCase(arrayAllData[2])) {
        fragment = new ChangePasswordFragment();
    } else if (tag.equalsIgnoreCase(arrayAllData[3])) {
        fragment = new MyWinningsFragment();
    } else if (tag.equalsIgnoreCase(arrayAllData[4])) {
        args.putBoolean("isAdmin", false);
        fragment = new CreateUserFragment();
    } else if (tag.equalsIgnoreCase(arrayAllData[5])) {
        fragment = new TransferPointsFragment();
    } else if (tag.equalsIgnoreCase(arrayAllData[6])) {
        //settings
        fragment = new ProfileFragment();
    }/*from w w w  .j  a  v  a 2s . c o m*/

    else if (tag.equalsIgnoreCase(arrayAllData[7])) {
        //signout
        signOut(true, null);
    } else if (tag.equalsIgnoreCase(arrayAllData[8])) {
        fragment = new CreateUserFragment();
        args.putBoolean("isAdmin", true);
    }

    fragment.setArguments(args);

    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);

    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:club.frickel.feelathome.DeviceFragment.java

private void onEffectSelected(Effect effect) {
    Fragment effectConfigFragment = null;
    assert effect.getConfig() != null;
    switch (effect.getName()) {
    case "Wheel":
    case "Wheel2":
    case "Rainbow":
    case "Sunrise":
    case "Stroboscope":
    case "Whitefade":
    case "Random Brightness":
    case "Random Fade":
    case "Random Color":
        effectConfigFragment = new OnlyOneDelayEffectConfigFragment();
        break;/*from w  ww .jav  a  2s . c om*/
    case "Color":
    case "Clock Color":
        effectConfigFragment = new OneColorEffectConfigFragment();
        break;
    case "Brightness":
    case "Brightness Scaling":
        effectConfigFragment = new BrightnessEffectConfigFragment();
        break;
    case "Colorfade":
        effectConfigFragment = new OneColorDelayEffectConfigFragment();
        break;
    case "Fire":
        effectConfigFragment = new FireEffectConfigFragment();
        break;
    case "Power": {
        effect.getConfig().put("Power", true);
        break;
    }
    }
    new SendStateHandler(effect, deviceID, getActivity()).execute();

    if (effectConfigFragment != null) {
        Bundle bundle = new Bundle();
        bundle.putString(Constants.DEVICE_ID, deviceID);
        bundle.putSerializable(Constants.EFFECT_STRING, effect);
        effectConfigFragment.setArguments(bundle);
        ((Main) getActivity()).replaceFragmentAndAddToBackstack(effectConfigFragment);
    }
}

From source file:com.polarion.starter.MainActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    mPreviousPosition = mCurrentPosition;
    mCurrentPosition = position;/*from   ww w .  ja  va2  s  .  co  m*/
    DrawerItem drawerItem = mDrawerAdapter.getItem(position);
    if (mToolbar != null && drawerItem != null) {
        mToolbar.setTitle(drawerItem.title);
    }
    FragmentManager fragmentManager = getFragmentManager();
    Fragment fragment;
    Bundle args;
    switch (position) {
    case MenuChoices.HOME:
        fragment = new HomeFragment();

        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment)
                .addToBackStack(HomeFragment.class.getSimpleName()).commit();
        break;
    case MenuChoices.AGENDA:
        fragment = new AgendaItemFragment();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment)
                .addToBackStack(AgendaItemFragment.class.getSimpleName()).commit();
        break;
    case MenuChoices.SPEAKERS:
        fragment = new SpeakerItemFragment();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment)
                .addToBackStack(SpeakerItemFragment.class.getSimpleName()).commit();
        break;
    case MenuChoices.PARTNERS:
        fragment = new WebFragment();
        args = new Bundle();
        args.putString(WebFragment.ARG_URL_PARAM, "http://54.183.27.217/2015m/partners/index.html");
        args.putString(WebFragment.ARG_TITLE_PARAM, "Partners");
        fragment.setArguments(args);
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment)
                .addToBackStack(LocationFragment.class.getSimpleName()).commit();
        break;

    case MenuChoices.MAP:
        fragment = new LocationFragment();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment)
                .addToBackStack(LocationFragment.class.getSimpleName()).commit();
        break;
    case MenuChoices.RAFFLE:
        ParseUser currentUser = ParseUser.getCurrentUser();
        if (currentUser == null) { // if user is not logged in then force login before entering raffle
            fragment = new LoginFragment();
            args = new Bundle();
            args.putString(LoginFragment.FROM_ACTIVITY, RaffleFragment.class.getSimpleName());
            fragment.setArguments(args);
            setTitle("Log In");
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment)
                    .addToBackStack(LoginFragment.class.getSimpleName()).commit();
        } else {
            fragment = new RaffleFragment();
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment)
                    .addToBackStack(RaffleFragment.class.getSimpleName()).commit();
        }
        break;
    case MenuChoices.LOGIN:
        fragment = new LoginFragment();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment)
                .addToBackStack(LoginFragment.class.getSimpleName()).commit();
        break;

    case MenuChoices.SOCIAL:
        fragment = new SocialFragment();
        //        args = new Bundle();
        //        args.putInt(DrawerFragment.ARG_DRAWER_NUMBER, position);
        //        fragment.setArguments(args);
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
        break;

    //      default :
    //        fragment = new DrawerFragment();
    //        args = new Bundle();
    //        args.putInt(DrawerFragment.ARG_DRAWER_NUMBER, position);
    //        fragment.setArguments(args);
    //        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
    //        break;
    }
    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);

    if (drawerItem != null)
        setTitle(drawerItem.title);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.samsung.msca.samsungvr.sampleapp.LoggedInFragment.java

private void selectItem(int position) {
    if (null == mUser || position == mCurrentSelection) {
        return;/*from w  w w  .j  a  v a2  s. c o  m*/
    }
    mCurrentSelection = position;
    mDrawerList.setItemChecked(position, true);
    mDrawerLayout.closeDrawer(mDrawerList);

    Bundle args = null;
    FragmentTransaction ft = mFragmentManager.beginTransaction();
    Fragment fragment = null;
    String tag = null;

    switch (position) {
    case 1: /* Create live event */

        tag = CreateLiveEventFragment.TAG;
        fragment = mFragmentManager.findFragmentByTag(tag);
        if (null == fragment) {
            fragment = CreateLiveEventFragment.newFragment();
        }
        args = new Bundle();
        args.putString(PARAM_USER, mUser.getUserId());
        break;

    case 2: /* List live events */

        tag = ListLiveEventsFragment.TAG;
        fragment = mFragmentManager.findFragmentByTag(tag);
        if (null == fragment) {
            fragment = ListLiveEventsFragment.newFragment();
        }
        args = new Bundle();
        args.putString(PARAM_USER, mUser.getUserId());
        break;

    case 3: /* Upload video */

        tag = UploadVideoFragment.TAG;
        fragment = mFragmentManager.findFragmentByTag(tag);
        if (null == fragment) {
            fragment = UploadVideoFragment.newFragment();
        }
        args = new Bundle();
        args.putString(PARAM_USER, mUser.getUserId());
        break;

    case 4: /* Get user by session id */

        tag = GetUserBySessionInfoFragment.TAG;
        fragment = mFragmentManager.findFragmentByTag(tag);
        if (null == fragment) {
            fragment = GetUserBySessionInfoFragment.newFragment();
        }
        break;

    }
    if (null != fragment && !fragment.isVisible()) {
        if (null != args) {
            fragment.setArguments(args);
        }
        ft.replace(R.id.content_frame, fragment, tag);
        ft.commitAllowingStateLoss();
    }
}

From source file:com.example.volunteerhandbook.MainActivity.java

private void selectItem(int position) {
    if (mPassword == null || mPassword.length() < 4) {
        checkPassword();//ww w. j  ava  2 s . c  o m
        return;
    }
    if (noDrawYet)
        return;
    if (position == mPageTitles.length - 1) {
        closeSpeaker();
        finish();
    }
    /*
    <item>0??</item>
    <item>1?</item>
    <item>2?</item>
    <item>3???</item>
    <item>4?</item>
    <item>5</item>        
    <item>6?</item>
    <item>7</item>
    <item>8</item>
    <item>9</item>
    <item>10</item>
    <item>11</item>
    <item>12??</item>
    */
    MenuItem.OnMenuItemClickListener aListener;
    Fragment fragment = null;
    ListRecordBase aList = null;
    Bundle args = new Bundle();
    switch (position) {
    case 0:
    case 1:
        openAgendaPage(null);
        return;
    case 2:
    case 3:
    case 4:
        setUpMyAgenda("Create New");
        return;
    case 6:
        openForumChatPage(null);
        return;
    case 10:
        openCommitmentPage(null);
        return;
    case 11:
        openPersonalPage(null);
        return;

    case 9:
    case 8:
    case 5:
        openMemoPage(null);
        return;

    case 7:
        aList = new VisitRecord();
        break;

    default:
        return;
    }

    args.putString(PAGE_TITLE, mPages[position]);
    aListener = aList;
    //String name=getResources().getStringArray(R.array.page_array_EN)[position];
    args.putInt(ListRecords.PARENT_PASSDOWN_KEY, position);
    fragment = (Fragment) aList;

    fragment.setArguments(args);
    mCurrentFragment = fragment;
    mCurrentPage = position;
    for (int i = 0; i < mActionMenu.size(); i++) {
        mActionMenu.getItem(i).setOnMenuItemClickListener(aListener);
    }
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.main_content_frame, fragment).commit();

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mPageTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.luke.lukef.lukeapp.MainActivity.java

/**
 * Switches the <code>fragment_container</code> RelativeLayout from <code>activity_main.xml</code> to the
 * fragment which is chosen.// ww w  .j a  va  2  s .c  o  m
 *
 * @param fragmentToChange Constants enum type defined for each fragment
 * @param bundleToSend     Optional bundle to send along with the transaction
 */
public void fragmentSwitcher(Constants.fragmentTypes fragmentToChange, Bundle bundleToSend) {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    Fragment fragment = null;
    String tag = "default";
    // cases are enumerations, create new fragment corresponding with the enum given
    switch (fragmentToChange) {
    case FRAGMENT_LEADERBOARD:
        fragment = new LeaderboardFragment();
        tag = "leader";
        break;
    case FRAGMENT_NEW_SUBMISSION:
        fragment = new NewSubmissionFragment();
        tag = "newSub";
        break;
    case FRAGMENT_PROFILE:
        fragment = new ProfileFragment();
        tag = "profile";
        break;
    case FRAGMENT_MAP:
        fragment = new MapViewFragment();
        tag = "map";
        break;
    default:
        fragment = null;
        break;
    }
    //replace the fragment
    if (bundleToSend != null && fragment != null) {
        fragment.setArguments(bundleToSend);
    }
    if (fragment != null) {
        fragmentTransaction.replace(R.id.fragment_container, fragment, tag).addToBackStack(tag).commit();

    }
}

From source file:com.android.eventspace.MainActivity.java

private void selectItem(int position) {
    Toast.makeText(getApplicationContext(), "number" + position, Toast.LENGTH_SHORT).show();
    FrameLayout f;// ww  w .  j  a v  a2s.com
    Fragment fragment;
    Bundle args;
    FragmentManager fragmentManager;
    switch (position) {
    case (3):

        f = (FrameLayout) findViewById(R.id.map_frame);
        f.setVisibility(View.GONE);
        final LatLng SITTERSON = new LatLng(35.910057, -79.053470);
        final LatLng OLDWELL = new LatLng(35.912045, -79.051181);

        GoogleMap googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        if (googleMap == null) {
            Toast.makeText(getApplicationContext(), "Sorry! unable to create maps", Toast.LENGTH_SHORT).show();
        } else {

            Marker hamburg = googleMap
                    .addMarker(new MarkerOptions().position(SITTERSON).title("My Second Home"));
            Marker kiel = googleMap
                    .addMarker(new MarkerOptions().position(OLDWELL).title("Oldwell").snippet("The Old Well")
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));

            googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(SITTERSON, 2));

            // Zoom in, animating the camera.
            googleMap.animateCamera(CameraUpdateFactory.zoomTo(21), 15000, null);

        }
        break;
    case 1:

        f = (FrameLayout) findViewById(R.id.map_frame);
        f.setVisibility(View.VISIBLE);

        // update the main content by replacing fragments
        fragment = new OptionFragment(position);
        args = new Bundle();
        args.putInt(OptionFragment.ARG_OPTION_NUMBER, position);
        fragment.setArguments(args);
        fragmentManager = getFragmentManager();

        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
        break;
    case 2:
        f = (FrameLayout) findViewById(R.id.map_frame);
        f.setVisibility(View.VISIBLE);

        // update the main content by replacing fragments
        fragment = new OptionFragment(position);
        args = new Bundle();
        args.putInt(OptionFragment.ARG_OPTION_NUMBER, position);
        fragment.setArguments(args);
        fragmentManager = getFragmentManager();

        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
        break;
    }

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(optionTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java

public void showHelp(final String url, boolean popBackStack, String titleId) {
    if (popBackStack) {
        popBackStackFull();//from   w ww .  ja  va  2  s.  c o m
    }

    FragmentTransaction ft;

    ft = fm.beginTransaction();

    final Fragment fragment = new RMBTHelpFragment();
    final Bundle args = new Bundle();

    args.putString(RMBTHelpFragment.ARG_URL, url);
    fragment.setArguments(args);
    ft.replace(R.id.fragment_content, fragment, titleId);
    ft.addToBackStack(titleId);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

    ft.commit();
    refreshActionBar(titleId);
}

From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java

/**
 * //w  w w  .j  a va  2  s .  c  om
 * @param uid
 */
public void showResultDetail(final String testUUid) {
    FragmentTransaction ft;

    final Fragment fragment = new RMBTTestResultDetailFragment();

    final Bundle args = new Bundle();

    args.putString(RMBTTestResultDetailFragment.ARG_UID, testUUid);
    fragment.setArguments(args);

    ft = fm.beginTransaction();
    ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_RESULT_DETAIL);
    ft.addToBackStack(AppConstants.PAGE_TITLE_RESULT_DETAIL);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.commit();

    refreshActionBar(AppConstants.PAGE_TITLE_RESULT_DETAIL);
}