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:com.concentricsky.android.khanacademy.app.HomeActivity.java

private void setListForTopic(final Topic topic, final Class<? extends AbstractListFragment<?>> fragmentClass,
        final boolean forward) {

    this.requestDataService(new ObjectCallback<KADataService>() {
        @Override// ww  w.  ja  va 2 s  . co  m
        public void call(KADataService dataService) {
            try {
                final Fragment frag = fragmentClass.newInstance();
                Bundle args = new Bundle();
                args.putString(PARAM_TOPIC_ID, topic.getId());
                frag.setArguments(args);

                // transition the fragments
                FragmentTransaction tx = getFragmentManager().beginTransaction()
                        .setBreadCrumbTitle(topic.getTitle());

                tx.replace(R.id.activity_home_list_container, frag, TAG_LIST_FRAGMENT).commit();

            } catch (InstantiationException e) {
                // Swallow this; we know that both AbstractListFragment subclasses have zero-arg constructors.
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // Swallow this; we know that both AbstractListFragment subclasses are visible here.
                e.printStackTrace();
            }
        }
    });

}

From source file:com.epitrack.guardioes.view.base.BaseAppCompatActivity.java

@Override
public int add(final Class<? extends Fragment> fragmentClass, final String tag, final Bundle bundle,
        final boolean addToBackStack) {

    if (fragmentClass == null) {
        throw new IllegalArgumentException("The fragmentClass cannot be null.");
    }//from ww  w.j a  va2  s.c  om

    if (tag == null) {
        throw new IllegalArgumentException("The tag cannot be null.");
    }

    if (fragmentMap == null) {
        fragmentMap = new ReferenceMap<>();
    }

    Fragment fragment = fragmentMap.get(tag);

    if (fragment == null) {

        fragment = Fragment.instantiate(this, fragmentClass.getName());

        fragmentMap.put(tag, fragment);
    }

    fragment.setArguments(bundle);

    if (addToBackStack) {

        return getFragmentManager().beginTransaction().add(getLayout(), fragment, tag).addToBackStack(tag)
                .commit();
    }

    return getFragmentManager().beginTransaction().add(getLayout(), fragment, tag).commit();
}

From source file:com.epitrack.guardioes.view.base.BaseAppCompatActivity.java

@Override
public int replace(final Class<? extends Fragment> fragmentClass, final String tag, final Bundle bundle,
        final boolean addToBackStack) {

    if (fragmentClass == null) {
        throw new IllegalArgumentException("The fragmentClass cannot be null.");
    }//ww w. j  ava2 s  .c om

    if (tag == null) {
        throw new IllegalArgumentException("The tag cannot be null.");
    }

    if (fragmentMap == null) {
        fragmentMap = new ReferenceMap<>();
    }

    Fragment fragment = fragmentMap.get(tag);

    if (fragment == null) {

        fragment = Fragment.instantiate(this, fragmentClass.getName());

        fragmentMap.put(tag, fragment);
    }

    fragment.setArguments(bundle);

    if (addToBackStack) {

        return getFragmentManager().beginTransaction().replace(getLayout(), fragment, tag).addToBackStack(tag)
                .commit();
    }

    return getFragmentManager().beginTransaction().replace(getLayout(), fragment, tag).commit();
}

From source file:rshankar.hindismsinhindi.MainActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new MessageFragment();
    Bundle args = new Bundle();
    args.putInt(MessageFragment.ARG_PLANET_NUMBER, position);
    args.putString("title", mCategories.get(position).getCategoryName());
    args.putInt("catId", mCategories.get(position).getCategoryId());
    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);
    setTitle(mPlanetTitles[position]);/*from ww  w .j  a va 2 s .  c o  m*/
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.autoparts.sellers.activity.MainDrawerActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new MainSellerFragment();
    Bundle args = new Bundle();
    //        args.putInt(SampleFragment.ARG_IMAGE_RES, mCityImages[position]);
    //        args.putInt(SampleFragment.ARG_ACTION_BG_RES, R.drawable.ab_background);
    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(drawer_view);
}

From source file:com.samsunghack.apps.android.noq.NavDrawerMainActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new PlanetFragment();
    Log.d(TAG, "+selectItem: positon = " + position);
    Bundle args = new Bundle();
    args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
    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);
    setTitle(mAppFeatureTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.example.ogadrive.HomeActivity2.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;

    if (position == 1) {
        /*fragment = new HomeFragement();
        fragment.setArguments(bundle);*/

        fragment = new FragmentHistory();
        fragment.setArguments(bundle);
    } else if (position == 0) {
        fragment = new FragmentProfile();
        fragment.setArguments(bundle);//from   w w  w .ja  va2s. c  o m

    } else if (position == 2) {

        setTitle("Contact Us");
    } else if (position == 3) {

        fragment = new FragmentHistory();
        fragment.setArguments(bundle);
    }

    if (fragment == null) {
        fragment = new HomeFragement();
        fragment.setArguments(bundle);
    }

    FragmentManager fragmentManager = getFragmentManager();
    // fragmentManager.popBackStack();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    fragmentTransaction.add(R.id.content_frame, fragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
    // fragmentTransaction.addToBackStack("hradesh").commit();
    // fragmentManager.getBackStackEntryAt(fragmentManager.getBackStackEntryCount()-1);

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

    // }
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.example.scheme.MyPalettesActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    mCurrentPos = position;/*ww  w.ja v a2  s. c  o  m*/
    Fragment fragment = new PaletteFragment();
    Bundle args = new Bundle();
    args.putInt(PaletteFragment.ARG_PALETTE_NUMBER, position);
    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);
    setTitle(mPaletteNames.get(position));
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:org.iota.wallet.ui.activity.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case Constants.REQUEST_CODE_LOGIN:
        inputManager.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
        navigationView.getMenu().performIdentifierAction(R.id.nav_wallet, 0);
    }/*from w w  w .  j av  a 2s  .c om*/
    if (data != null) {
        if (Intent.ACTION_VIEW.equals(data.getAction())) {
            QRCode qrCode = new QRCode();
            Uri uri = data.getData();
            qrCode.setAddress(uri.getQueryParameter("address:"));
            qrCode.setAddress(uri.getQueryParameter("amount:"));
            qrCode.setAddress(uri.getQueryParameter("message:"));

            Bundle bundle = new Bundle();
            bundle.putParcelable(Constants.QRCODE, qrCode);

            Fragment fragment = new NewTransferFragment();
            fragment.setArguments(bundle);
            showFragment(fragment, true);
        }
    }
}

From source file:com.battlelancer.seriesguide.ui.SeriesGuidePreferences.java

public void switchToSettings(String settingsId) {
    Bundle args = new Bundle();
    args.putString("settings", settingsId);
    Fragment f = new SettingsFragment();
    f.setArguments(args);
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.content_frame, f);/*from   ww  w.  j  av a2  s .c  om*/
    ft.addToBackStack(null);
    ft.commit();
}