Java Code Examples for android.support.v4.app.fragment#setArguments()
The following examples show how to use
android.support.v4.app.fragment#setArguments() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SetCustomFragmentActivity.java From AdvancedMaterialDrawer with Apache License 2.0 | 6 votes |
@Override public void init(Bundle savedInstanceState) { drawer = this; // create menu MaterialMenu menu = new MaterialMenu(); menu.add(new MaterialItemSectionFragment(this, "Section 1", new FragmentDummy(), "Section 1")); menu.add(new MaterialItemSectionFragment(this, "Section 2", new FragmentDummy(), "Section 2")); menu.add(new MaterialItemSectionFragment(this, "Section 3", new FragmentDummy(), "Section 3")); // load menu this.loadMenu(menu); // information text for the fragment Bundle bundle = new Bundle(); bundle.putString("instruction", "This activity starts with a custom fragment. " + "It's not from the menu."); Fragment fragmentInstruction = new FragmentInstruction(); fragmentInstruction.setArguments(bundle); // set custom fragment this.changeFragment(fragmentInstruction, "Custom Fragment Instruction"); }
Example 2
Source File: StagesFragment.java From triviums with MIT License | 6 votes |
public void loadFragment() { Fragment fragment = new QuestionFragment(); FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); Bundle args = new Bundle(); args.putString("categoryId", categoryId); args.putString("categoryName", categoryName); args.putString("stageNumber", String.valueOf(button.getText())); args.putInt("currentScore", currentScore); args.putInt("totalPages", totalPage.size()); fragment.setArguments(args); transaction.replace(R.id.fragment_container, fragment) .addToBackStack(null) .commit(); }
Example 3
Source File: OnlyIconsActivity.java From AdvancedMaterialDrawer with Apache License 2.0 | 6 votes |
@Override public void init(Bundle savedInstanceState) { drawer = this; // information text for the fragment Bundle bundle = new Bundle(); bundle.putString("instruction", "The Menu has Only Icons"); Fragment fragmentInstruction = new FragmentInstruction(); fragmentInstruction.setArguments(bundle); // create menu MaterialMenu menu = new MaterialMenu(); menu.add(new MaterialItemSectionFragment(this, this.getResources().getDrawable(R.drawable.app_drawer_icon) , true, new FragmentDummy(), "Fragment Section Icon Banner")); menu.add(new MaterialItemSectionFragment(this, this.getResources().getDrawable(R.drawable.ic_extension_black_36dp) , true, new FragmentDummy(), "Extension")); menu.add(new MaterialItemSectionFragment(this, this.getResources().getDrawable(R.drawable.ic_list_black_36dp) , true, new FragmentDummy(), "List")); menu.add(new MaterialItemSectionFragment(this, this.getResources().getDrawable(R.drawable.ic_favorite_black_36dp) , true, new FragmentDummy(), "Favorite").setSectionColor(Color.parseColor("#ff0858"))); // load menu this.loadMenu(menu); // load the MaterialItemSectionFragment, from the given startIndex this.loadStartFragmentFromMenu(menu); }
Example 4
Source File: TaxActivityHandler.java From mobikul-standalone-pos with MIT License | 6 votes |
public void addTax() { FragmentManager fragmentManager = ((AppCompatActivity) context).getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left); Fragment fragment; fragment = ((BaseActivity) context).mSupportFragmentManager.findFragmentByTag(AddTaxFragment.class.getSimpleName()); if (fragment == null) fragment = new AddTaxFragment(); if (!fragment.isAdded()) { Bundle bundle = new Bundle(); bundle.putSerializable("tax", new Tax()); bundle.putBoolean("edit", false); fragment.setArguments(bundle); fragmentTransaction.add(((TaxActivity) context).binding.taxFl.getId(), fragment, fragment.getClass().getSimpleName()); fragmentTransaction.addToBackStack(fragment.getClass().getSimpleName()).commit(); } }
Example 5
Source File: BaseFragmentActivity.java From BigApp_WordPress_Android with Apache License 2.0 | 6 votes |
/*** * 显示跳转界面, add * * @param fragment * @param extras * @param back */ protected void showFragmentAdd(int layoutId, Fragment fragment, Bundle extras, boolean back, String fragmentTag) { if (fragment != null) { if (extras != null) { fragment.setArguments(extras); } FragmentTransaction transaction = getSupportFragmentManager() .beginTransaction(); if (back) { transaction.setCustomAnimations(R.anim.v_roll_up, R.anim.v_roll_down); } else { // 定义进入和退出的动画 transaction.setCustomAnimations(R.anim.v_roll_up, R.anim.v_roll_down, R.anim.v_roll_up, R.anim.v_roll_down); } transaction.add(layoutId, fragment, fragmentTag).commit(); transaction.addToBackStack(fragmentTag); transaction = null; } }
Example 6
Source File: FragmentNavigationDrawer.java From example with Apache License 2.0 | 6 votes |
/** * Swaps fragments in the main content view */ public void selectDrawerItem(int position) { // Create a new fragment and specify the planet to show based on // position FragmentNavItem navItem = drawerNavItems.get(position); Fragment fragment = null; try { fragment = navItem.getFragmentClass().newInstance(); Bundle args = navItem.getFragmentArgs(); if (args != null) { fragment.setArguments(args); } } catch (Exception e) { e.printStackTrace(); } // Insert the fragment by replacing any existing fragment FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); fragmentManager.beginTransaction().replace(drawerContainerRes, fragment).commit(); // Highlight the selected item, update the title, and close the drawer lvDrawer.setItemChecked(position, true); setTitle(navItem.getTitle()); closeDrawer(lvDrawer); }
Example 7
Source File: SubredditSearch.java From Slide with GNU General Public License v3.0 | 6 votes |
@Override public void onCreate(Bundle savedInstance) { super.onCreate(savedInstance); term = getIntent().getExtras().getString("term"); applyColorTheme(""); setContentView(R.layout.activity_fragmentinner); setupAppBar(R.id.toolbar, term, true, true); Fragment f = new SubredditListView(); Bundle args = new Bundle(); args.putString("id", term); f.setArguments(args); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.fragmentcontent, f); fragmentTransaction.commit(); }
Example 8
Source File: AFragment.java From SwipeBack with Apache License 2.0 | 5 votes |
public static Fragment newInstance(String content) { Fragment fragment = new AFragment(); Bundle bundle = new Bundle(); bundle.putString("content",content); fragment.setArguments(bundle); return fragment; }
Example 9
Source File: PictureActivity.java From actor-platform with GNU Affero General Public License v3.0 | 5 votes |
public static Fragment getInstance(String path, int senderId) { Bundle bundle = new Bundle(); bundle.putString(ARG_FILE_PATH, path); bundle.putInt(ARG_OWNER, senderId); Fragment fragment = new PictureFragment(); fragment.setArguments(bundle); return fragment; }
Example 10
Source File: CommentDetailFragment.java From NovelReader with MIT License | 5 votes |
public static Fragment newInstance(String detailId){ Bundle bundle = new Bundle(); bundle.putSerializable(EXTRA_DETAIL_ID,detailId); Fragment fragment = new CommentDetailFragment(); fragment.setArguments(bundle); return fragment; }
Example 11
Source File: IconPageIndicatorActivity.java From android-opensource-library-56 with Apache License 2.0 | 5 votes |
@Override public Fragment getItem(int position) { Fragment f = new SampleFragment(); Bundle args = new Bundle(); args.putInt(SampleFragment.PAGE_NUMBER, position + 1); f.setArguments(args); return f; }
Example 12
Source File: HeadItemFiveExtraMenuActivity.java From AdvancedMaterialDrawer with Apache License 2.0 | 5 votes |
private MaterialHeadItem getHeadItem1() { // information text for the fragment Bundle bundle = new Bundle(); bundle.putString("instruction", "This example shows the head item style with five items. \" +\n" + " \"The first three head items ar shown with a picture. To get the other head items, \" +\n" + " \"press the down arrow button in the header. \" +\n" + " \"Under the items, you see the extra menu."); Fragment fragmentInstruction = new FragmentInstruction(); fragmentInstruction.setArguments(bundle); // create menu MaterialMenu menu = new MaterialMenu(); menu.add(new MaterialItemSectionFragment(this, "Instruction", fragmentInstruction, "Switcher Extra Menu (Five Items)")); menu.add(new MaterialItemSectionFragment(this, "Section 1", new FragmentDummy(), "Section 1")); menu.add(new MaterialItemSectionFragment(this, "Section 2", new FragmentDummy(), "Section 2")); menu.add(new MaterialItemSectionFragment(this, "Section 3", new FragmentDummy(), "Section 3")); // create Head Item // use bitmap and make a circle photo final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.head_item_icon); final RoundedCornersDrawable drawableAppIcon = new RoundedCornersDrawable(getResources(), bitmap); MaterialHeadItem headItem = new MaterialHeadItem(this, "A HeadItem", "A Subtitle", drawableAppIcon, R.drawable.mat1, menu); return headItem; }
Example 13
Source File: BackPatternDefaultActivity.java From AdvancedMaterialDrawer with Apache License 2.0 | 5 votes |
@Override public void init(Bundle savedInstanceState) { drawer = this; // information text for the fragment Bundle bundle = new Bundle(); bundle.putString("instruction", "Default back pattern. It only calls super.onBackPressed() ."); Fragment fragmentInstruction = new FragmentInstruction(); fragmentInstruction.setArguments(bundle); // create menu MaterialMenu menu = new MaterialMenu(); menu.add(new MaterialItemSectionFragment(this, "Instruction", fragmentInstruction, "Default Back Pattern")); menu.add(new MaterialItemSectionFragment(this, "Section 1", new FragmentDummy(), "Section 1")); menu.add(new MaterialItemSectionFragment(this, "Section 2", new FragmentDummy(), "Section 2")); menu.add(new MaterialItemSectionFragment(this, "Section 3", new FragmentDummy(), "Section 3")); // load menu this.loadMenu(menu); // load first MaterialItemSectionFragment in the menu, because there is no start position this.loadStartFragmentFromMenu(menu); // set back pattern this.setBackPattern(MaterialNavigationDrawer.BACKPATTERN_BACK_ANYWHERE); }
Example 14
Source File: BaseEmptyFragmentActivity.java From CameraMaskDemo with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getIntent().getBooleanExtra(EXTRA_FULL_SCREEN, false)) { //without ActionBar requestWindowFeature(Window.FEATURE_NO_TITLE); if (getSupportActionBar() != null) getSupportActionBar().hide(); //show full screen getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } else { if (getIntent().getBooleanExtra(EXTRA_SHOW_ACTION_BAR, true)) { initActionBar(getSupportActionBar()); } else if (getSupportActionBar() != null) { getSupportActionBar().hide(); } } String className = getIntent().getStringExtra(EXTRA_FRAGMENT_CLASS_NAME); if (className != null && className.length() > 0) { Class<?> clzz = null; Object obj = null; try { clzz = Class.forName(className); obj = clzz.newInstance(); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { e.printStackTrace(); } if (obj instanceof Fragment) { Fragment fragment = (Fragment) obj; Bundle arguments = getIntent().getExtras(); if (arguments != null) { fragment.setArguments(arguments); } getSupportFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit(); } } }
Example 15
Source File: Navigator.java From outlay with Apache License 2.0 | 5 votes |
private static void changeFragment(FragmentActivity activityFrom, Class<?> clazz, Bundle b) { String className = clazz.getName(); Fragment f = Fragment.instantiate(activityFrom, className); f.setArguments(b); activityFrom.getSupportFragmentManager() .beginTransaction() .replace(app.outlay.R.id.fragment, f, className) .addToBackStack(className) .commit(); }
Example 16
Source File: HelpsDetailFragment.java From NovelReader with MIT License | 5 votes |
public static Fragment newInstance(String detailId){ Bundle bundle = new Bundle(); bundle.putSerializable(EXTRA_DETAIL_ID,detailId); Fragment fragment = new HelpsDetailFragment(); fragment.setArguments(bundle); return fragment; }
Example 17
Source File: HeadItemThreeActivity.java From AdvancedMaterialDrawer with Apache License 2.0 | 5 votes |
private MaterialHeadItem getHeadItem1() { // information text for the fragment Bundle bundle = new Bundle(); bundle.putString("instruction", "This example shows the head item style with five items. " + "The first three head items ar shown with a picture. To get the other head items, " + "press the down arrow button in the header."); Fragment fragmentInstruction = new FragmentInstruction(); fragmentInstruction.setArguments(bundle); // create menu MaterialMenu menu = new MaterialMenu(); menu.add(new MaterialItemSectionFragment(this, "Instruction", fragmentInstruction, "Head Item Style (Three Items)")); menu.add(new MaterialItemSectionFragment(this, "Section 1", new FragmentDummy(), "Section 1")); menu.add(new MaterialItemSectionFragment(this, "Section 2", new FragmentDummy(), "Section 2")); menu.add(new MaterialItemSectionFragment(this, "Section 3", new FragmentDummy(), "Section 3")); // create Head Item // use bitmap and make a circle photo final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.head_item_icon); final RoundedCornersDrawable drawableAppIcon = new RoundedCornersDrawable(getResources(), bitmap); MaterialHeadItem headItem = new MaterialHeadItem(this, "A HeadItem", "A Subtitle", drawableAppIcon, R.drawable.mat1, menu); return headItem; }
Example 18
Source File: HomeMediasFragment.java From meiShi with Apache License 2.0 | 5 votes |
public static Fragment newInstance(int id, int type) { Bundle bundle = new Bundle(); bundle.putInt(KEY_VIDEO_ID, id); bundle.putInt(KEY_VIDEO_TYPE, type); Fragment fragment = new HomeMediasFragment(); fragment.setArguments(bundle); return fragment; }
Example 19
Source File: RegisterActivity.java From school_shop with MIT License | 4 votes |
@Override public void changeFragment(int position,String phone) { Fragment fragment = null; switch (position) { case 0: fragment = new PhoneFragment_(); guide1.setTextColor(getResources().getColor(R.color.statusbar_bg)); break; case 1: fragment = new Verifyfragment_(); runOnUiThread(new Runnable() { @Override public void run() { guide1.setTextColor(getResources().getColor(R.color.statusbar_bg)); guide2.setTextColor(getResources().getColor(R.color.statusbar_bg)); } }); break; case 2: fragment = new RegisterFragment_(); runOnUiThread(new Runnable() { @Override public void run() { guide1.setTextColor(getResources().getColor(R.color.statusbar_bg)); guide2.setTextColor(getResources().getColor(R.color.statusbar_bg)); guide3.setTextColor(getResources().getColor(R.color.statusbar_bg)); } }); break; default: break; } if(phone!=null){ Bundle bundle = new Bundle(); bundle.putString("phone",phone); fragment.setArguments(bundle); } if(fragment!=null){ getSupportFragmentManager().beginTransaction().replace(R.id.registerContent,fragment,"SHARE_FRAGMENT").commit(); } }
Example 20
Source File: UIHelper.java From iSCAU-Android with GNU General Public License v3.0 | 2 votes |
/** * help to replace fragment and set the arguments * @param act * @param fragment * @param objects the format such as "target"(key),"1"(value),"mode","all" .... */ public static void startFragment(ActionBarActivity act, Fragment fragment, Object... objects){ fragment.setArguments(buildBundle(objects)); startFragment(act,fragment); }