List of usage examples for android.app FragmentTransaction replace
public abstract FragmentTransaction replace(@IdRes int containerViewId, Fragment fragment, String tag);
From source file:io.demiseq.jetreader.activities.MainActivity.java
private void GetHotMangas() { MainFragment fragment = new MainFragment(); Bundle args = new Bundle(); args.putInt("manga_type", 1); fragment.setArguments(args);//from w w w. j a v a 2 s . com FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.content_frame, fragment, "HOT"); fragmentTransaction.commit(); removeSpinner(); setTitle(app_name); }
From source file:io.demiseq.jetreader.activities.MainActivity.java
private void GetFavoriteMangas() { MainFragment fragment = new MainFragment(); Bundle args = new Bundle(); args.putInt("manga_type", 2); fragment.setArguments(args);/*from w w w . j a v a2 s.c om*/ FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.content_frame, fragment, "FAVOURITE"); fragmentTransaction.commit(); removeSpinner(); setTitle(favorite); }
From source file:com.prasanna.android.stacknetwork.QuestionActivity.java
private void showCommentFragment(long postId, ArrayList<Comment> comments) { String fragmentTag = postId + "-" + StringConstants.COMMENTS; commentFragment = findFragmentByTag(fragmentTag, CommentFragment.class); if (commentFragment == null) { commentFragment = new CommentFragment(); commentFragment.setComments(comments); commentFragment.setResultReceiver(resultReceiver); String currentViewPagerFragmentTag = "android:switcher:" + R.id.viewPager + ":" + viewPager.getCurrentItem(); OnCommentChangeListener onCommentChangeListener = (OnCommentChangeListener) getFragmentManager() .findFragmentByTag(currentViewPagerFragmentTag); if (onCommentChangeListener != null) commentFragment.setOnCommentChangeListener(onCommentChangeListener); }//from w w w. j a v a2s. co m FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.fragmentContainer, commentFragment, fragmentTag); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.addToBackStack(fragmentTag); transaction.commit(); }
From source file:io.demiseq.jetreader.activities.MainActivity.java
private void GetCategories(Category c) { if (spinnerContainer == null) setUpSpinner();// www . j a v a 2 s . c om CategoryFragment fragment = new CategoryFragment(); Bundle bundle = new Bundle(); bundle.putString("url", c.getUrl()); bundle.putInt("max_page", c.getPage()); bundle.putInt("position", categories.indexOf(c)); fragment.setArguments(bundle); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.content_frame, fragment, "CATEGORY"); fragmentTransaction.commit(); }
From source file:me.pzheng.conn.MainActivity.java
@Override public void onNavigationDrawerItemSelected(int position) { // update the main content by replacing fragments FragmentManager fm = getFragmentManager(); FragmentTransaction transaction = fm.beginTransaction(); // debug code // Toast.makeText(this, "Menu item selected -> " + position, Toast.LENGTH_SHORT).show(); Fragment fragment;//from w w w .j a v a 2 s . co m switch (position) { case 0: //connect fragment = fm.findFragmentByTag(ConnectFragment.TAG); if (fragment == null) { fragment = new ConnectFragment(); } transaction.replace(R.id.container, fragment, ConnectFragment.TAG); transaction.addToBackStack(null); transaction.commit(); break; case 1: //settings /* fragment = getFragmentManager().findFragmentByTag(StatsFragment.TAG); if (fragment == null) { fragment = new StatsFragment(); } getFragmentManager().beginTransaction().replace(R.id.container, fragment, StatsFragment.TAG).commit(); */ fragment = fm.findFragmentByTag(SettingsFragment.TAG); if (fragment == null) { fragment = new SettingsFragment(); } transaction.replace(R.id.container, fragment, SettingsFragment.TAG); transaction.addToBackStack(null); transaction.commit(); break; case 2: //about fragment = fm.findFragmentByTag(AboutFragment.TAG); if (fragment == null) { fragment = new AboutFragment(); } transaction.replace(R.id.container, fragment, AboutFragment.TAG); transaction.addToBackStack(null); transaction.commit(); break; } //transaction.commit(); }
From source file:com.android.mail.ui.OnePaneController.java
/** * Replace the content_pane with the fragment specified here. The tag is specified so that * the {@link ActivityController} can look up the fragments through the * {@link android.app.FragmentManager}./*from w ww . j a v a 2 s. co m*/ * @param fragment the new fragment to put * @param transition the transition to show * @param tag a tag for the fragment manager. * @param anchor ID of view to replace fragment in * @return transaction ID returned when the transition is committed. */ private int replaceFragment(Fragment fragment, int transition, String tag, int anchor) { final FragmentManager fm = mActivity.getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.setTransition(transition); fragmentTransaction.replace(anchor, fragment, tag); final int id = fragmentTransaction.commitAllowingStateLoss(); fm.executePendingTransactions(); return id; }
From source file:com.ternup.caddisfly.fragment.ResultFragment.java
private void goBack() { FragmentManager fm = getFragmentManager(); try {/* w ww. jav a 2 s . co m*/ if (fm.getBackStackEntryCount() > 0) { fm.popBackStack(); fm.executePendingTransactions(); } else { Fragment fragment = new HomeFragment(); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.executePendingTransactions(); FragmentTransaction ft = fragmentManager.beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.replace(R.id.container, fragment, "0"); ft.addToBackStack(null); ft.commit(); fm.executePendingTransactions(); ListView drawerList = (ListView) getActivity().findViewById(R.id.navigation_drawer); drawerList.setItemChecked(0, true); drawerList.setSelection(0); } } catch (Exception e) { e.printStackTrace(); } }
From source file:blackman.matt.infinitebrowser.InfinityBrowser.java
/** * Creates a new board for a post when reply button is hit. * * @param boardRoot Link to the thread to open up * @param threadNo Thread no being opened *//* www . j av a 2 s. co m*/ @Override public void onReplyClicked(String boardRoot, String threadNo) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); Boolean ageAccept = preferences.getBoolean("age_guard_accept", false); if (ageAccept) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); LinearLayout helpText = (LinearLayout) findViewById(R.id.ll_help_add_boards); Board newThread = Board.newInstance(boardRoot, threadNo); fragmentTransaction.replace(R.id.container, newThread, threadNo); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); helpText.setVisibility(View.GONE); mTitle = boardRoot.replace("https://8chan.co", "") + threadNo; setTitle(mTitle); } }
From source file:com.ternup.caddisfly.fragment.DetailsFragment.java
private void goBack() { FragmentManager fm = getFragmentManager(); try {//from w w w . j av a 2 s. c om if (fm.getBackStackEntryCount() > 0) { fm.popBackStack(); fm.executePendingTransactions(); } else { Fragment fragment = new HomeFragment(); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.replace(R.id.container, fragment, "0"); ft.addToBackStack(null); ft.commit(); fm.executePendingTransactions(); ListView drawerList = (ListView) getActivity().findViewById(R.id.navigation_drawer); drawerList.setItemChecked(0, true); drawerList.setSelection(0); } } catch (Exception e) { e.printStackTrace(); } }
From source file:blackman.matt.infinitebrowser.NavigationDrawerFragment.java
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. *//*from ww w . j a v a 2 s.c o m*/ public void setUp(int fragmentId, DrawerLayout drawerLayout) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.navigation_drawer_open, /* "open drawer" description for accessibility */ R.string.navigation_drawer_close /* "close drawer" description for accessibility */ ) { /** * Handles the drawer being closed. * * @param drawerView The drawer being closed. */ @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } /** * Handles the drawer being opened. * * @param drawerView The drawer being opened. */ @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } if (!mUserLearnedDrawer) { // The user manually opened the drawer; store this flag to prevent auto-showing // the navigation drawer automatically in the future. mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); } setUpListAdapter(); getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String boardRoot = "/tech/"; if (view instanceof TextView) { boardRoot = ((TextView) view).getText().toString(); } FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Board newBoard = Board.newInstance(boardRoot); fragmentTransaction.replace(R.id.container, newBoard, boardRoot); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); closeDrawer(); } }); // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. if (!mUserLearnedDrawer && !mFromSavedInstanceState) { mDrawerLayout.openDrawer(mFragmentContainerView); } // Defer code dependent on restoration of previous instance state. mDrawerLayout.post(new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }