Java Code Examples for android.support.v4.app.FragmentTransaction#replace()

The following examples show how to use android.support.v4.app.FragmentTransaction#replace() . 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: FragmentCustomAnimationSupport.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
void addFragmentToStack() {
    mStackLevel++;

    // Instantiate a new fragment.
    Fragment newFragment = CountingFragment.newInstance(mStackLevel);

    // Add the fragment to the activity, pushing this transaction
    // on to the back stack.
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.anim.fragment_slide_left_enter,
            R.anim.fragment_slide_left_exit,
            R.anim.fragment_slide_right_enter,
            R.anim.fragment_slide_right_exit);
    ft.replace(R.id.simple_fragment, newFragment);
    ft.addToBackStack(null);
    ft.commit();
}
 
Example 2
Source File: IssueDetailsActivity.java    From magpi-android with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_issue_details);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    issueFragment.setArguments(getIntent().getExtras());
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.fragment_container, issueFragment);
    transaction.commit();
}
 
Example 3
Source File: ActivityUtils.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
/**
 * 替换Activity中的Fragment
 * @param fragmentManager fragment管理器
 * @param fragment  需要替换到Activity的Fragment
 * @param frameId  布局FrameLayout的Id
 */
public static void replaceFragmentFromActivity(FragmentManager fragmentManager, Fragment fragment, int frameId) {
    if (null != fragmentManager && null != fragment) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(frameId, fragment);
        transaction.commit();
    }
}
 
Example 4
Source File: GeoARActivity.java    From geoar-app with Apache License 2.0 5 votes vote down vote up
private void showFragment(Fragment fragment) {
	if (fragment.isAdded()) {
		return;
	}
	getSupportFragmentManager().executePendingTransactions();
	FragmentTransaction transaction = getSupportFragmentManager()
			.beginTransaction();
	transaction.replace(R.id.fragmentContainer, fragment);
	transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
	transaction.commit();
}
 
Example 5
Source File: MainActivity.java    From android-SwipeRefreshLayoutBasic with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        SwipeRefreshLayoutBasicFragment fragment = new SwipeRefreshLayoutBasicFragment();
        transaction.replace(R.id.sample_content_fragment, fragment);
        transaction.commit();
    }
}
 
Example 6
Source File: MainActivity.java    From FragmentAnimations with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ButterKnife.bind(this);

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.layout_main, ExampleFragment.newInstance(ExampleFragment.NODIR));
    ft.commit();
}
 
Example 7
Source File: MainActivity.java    From memoir with Apache License 2.0 5 votes vote down vote up
private void setSelectedDrawerItem(int position) {
    currentPosition = position;

    MenuItem item = navigationView.getMenu().getItem(position);
    item.setChecked(true);

    if (position == 0) {
        getSupportActionBar().setTitle(R.string.app_name);
    } else {
        getSupportActionBar().setTitle(item.getTitle());
    }

    Fragment fragment;
    if (position == 0) {
        fragment = new NotesFragment();
    } else if (position == 1) {
        fragment = new CalendarFragment();
    } else {
        fragment = new AtlasFragment();
    }
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.content_frame, fragment);
    transaction.commit();

    // Save position to preference
    SharedPreferences preferences = getPreferences(Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putInt(LAST_SELECTION_KEY, position);
    editor.apply();
}
 
Example 8
Source File: RegisterActivity.java    From firebase-chat with MIT License 5 votes vote down vote up
private void init() {
    // set the toolbar
    setSupportActionBar(mToolbar);

    // set the register screen fragment
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.frame_layout_content_register,
            RegisterFragment.newInstance(),
            RegisterFragment.class.getSimpleName());
    fragmentTransaction.commit();
}
 
Example 9
Source File: MainActivity.java    From android-multibackstack with Apache License 2.0 5 votes vote down vote up
private void replaceFragment(@NonNull Fragment fragment) {
  FragmentManager fm = getSupportFragmentManager();
  FragmentTransaction tr = fm.beginTransaction();
  tr.replace(R.id.content, fragment);
  tr.commitAllowingStateLoss();
  curFragment = fragment;
}
 
Example 10
Source File: FragmentStackFragmentSupport.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
void addFragmentToStack() {
    mStackLevel++;

    // Instantiate a new fragment.
    Fragment newFragment = FragmentStackSupport.CountingFragment.newInstance(mStackLevel);

    // Add the fragment to the activity, pushing this transaction
    // on to the back stack.
    FragmentTransaction ft = getChildFragmentManager().beginTransaction();
    ft.replace(R.id.simple_fragment, newFragment);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.addToBackStack(null);
    ft.commit();
}
 
Example 11
Source File: FragmentUtils.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
/**
     * v4的replace
     *
     * @param fragmentManager
     * @param idContainer
     * @param fragement
     */
    public static void replace(FragmentManager fragmentManager, int idContainer, Fragment fragement, BundleData bundleData) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
// Replace whatever is in thefragment_container view with this fragment,
// and add the transaction to the backstack
        pushData(fragement, bundleData);
        transaction.replace(idContainer, fragement);
        transaction.addToBackStack(null);
//提交修改
        transaction.commitAllowingStateLoss();
    }
 
Example 12
Source File: ChatActivity.java    From FirebaseMessagingApp with GNU General Public License v3.0 5 votes vote down vote up
private void init() {
    // set the toolbar
    setSupportActionBar(mToolbar);

    // set toolbar title
    mToolbar.setTitle(getIntent().getExtras().getString(Constants.ARG_RECEIVER));



  //
    FirebaseDatabase.getInstance().getReference().child("users")
            .child(getIntent().getExtras().get(Constants.ARG_RECEIVER_UID).toString())
            .child("status").addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            try{
            mToolbar.setSubtitle(dataSnapshot.getValue().toString());}catch (Exception e){
            //no status
        }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });





    // set the register screen fragment
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.frame_layout_content_chat,
            ChatFragment.newInstance(getIntent().getExtras().getString(Constants.ARG_RECEIVER),
                    getIntent().getExtras().getString(Constants.ARG_RECEIVER_UID),
                    getIntent().getExtras().getString(Constants.ARG_FIREBASE_TOKEN)),
            ChatFragment.class.getSimpleName());
    fragmentTransaction.commit();
}
 
Example 13
Source File: BaseActivity.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
private void setCurrentFragment(Fragment fragment, String tag, boolean needAddToBackStack) {
    currentFragment = fragment;
    FragmentTransaction transaction = buildTransaction();
    if (needAddToBackStack) {
        transaction.addToBackStack(null);
    }
    transaction.replace(R.id.container_fragment, fragment, tag);
    transaction.commit();
}
 
Example 14
Source File: MainActivity.java    From notSABS with MIT License 5 votes vote down vote up
public void editLayoutClick(View view) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit);
        fragmentTransaction.replace(R.id.fragmentContainer, new BlockedUrlSettingFragment());
        fragmentTransaction.addToBackStack("main_to_editUrl");
        fragmentTransaction.commit();
}
 
Example 15
Source File: MainActivity.java    From android-credentials with Apache License 2.0 5 votes vote down vote up
public void setFragment(boolean isVerifying) {
    Fragment current = getCurrentFragment();
    Fragment frag = statusFrag;
    if (isVerifying) {
        frag = validationFrag;
    }
    if (current == null || frag.getId() != current.getId()) {
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(container.getId(), frag);
        transaction.commitAllowingStateLoss();
    }
}
 
Example 16
Source File: MainActivity.java    From notSABS with MIT License 5 votes vote down vote up
public void alloAppsLayout(View view) {
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit);
    fragmentTransaction.replace(R.id.fragmentContainer, new AppListFragment());
    fragmentTransaction.addToBackStack("main_to_editApp");
    fragmentTransaction.commit();
    Objects.requireNonNull(MainActivity.this).setTitle(R.string.edit_blocked_apps_list);
}
 
Example 17
Source File: MainActivity.java    From ui with Apache License 2.0 4 votes vote down vote up
@Override
public void onTabSelected( Tab tab, FragmentTransaction ft )
{
	mFragment = Fragment.instantiate( mActivity, mFragName );
	ft.replace( android.R.id.content, mFragment );
}
 
Example 18
Source File: EditorActivity.java    From CameraV with GNU General Public License v3.0 4 votes vote down vote up
private void initLayout()
{
	Bundle fullscreenViewArgs = new Bundle();
	Bundle detailsViewArgs = new Bundle();

	fullscreenViewArgs.putInt(Codes.Extras.SET_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	fullscreenViewArgs.putString("mediaId", mediaId);
	detailsViewArgs.putInt(Codes.Extras.SET_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	detailsViewArgs.putString("mediaId", mediaId);

	if (media.dcimEntry.mediaType.equals(Models.IMedia.MimeType.IMAGE))
	{
		fullscreenView = Fragment.instantiate(this, FullScreenImageViewFragment.class.getName(), fullscreenViewArgs);
		mediaHolderView = ((FullScreenImageViewFragment)fullscreenView).getImageView();			
	}
	else if ( media.dcimEntry.fileAsset.source == Storage.Type.IOCIPHER)
	{
		fullscreenView = Fragment.instantiate(this, FullScreenMJPEGViewFragment.class.getName(), fullscreenViewArgs);
		//fullscreenView = Fragment.instantiate(this, FullScreenMJPEGPlayerFragment.class.getName(), fullscreenViewArgs);
	}
	else if (media.dcimEntry.mediaType.startsWith(Models.IMedia.MimeType.VIDEO_BASE))
	{
		fullscreenView = Fragment.instantiate(this, FullScreenVideoViewFragment.class.getName(), fullscreenViewArgs);
	}

	detailsView = (OverviewFormFragment) Fragment.instantiate(this, OverviewFormFragment.class.getName(), detailsViewArgs);

	formView = Fragment.instantiate(this, TagFormFragment.class.getName());

	actionBar.setDisplayShowTitleEnabled(true);
	actionBar.setDisplayShowHomeEnabled(true);
	actionBar.setDisplayHomeAsUpEnabled(false);
	actionBar.setHomeButtonEnabled(true);
	actionBar.setLogo(this.getResources().getDrawable(R.drawable.ic_action_up));
	actionBar.setDisplayUseLogoEnabled(true);

	FragmentTransaction ft = fm.beginTransaction();
	ft.replace(R.id.media_holder, fullscreenView);
	ft.replace(R.id.details_form_holder, detailsView);
	ft.replace(R.id.root_form, formView);
	ft.addToBackStack(null);
	ft.commit();
	
	
	updateUIBasedOnActionMode();
	
	
}
 
Example 19
Source File: ActivityUtils.java    From ESeal with Apache License 2.0 4 votes vote down vote up
public static void replaceFragmentToActivity(@NonNull FragmentManager fragmentManager,
                                             @NonNull Fragment fragment, int frameId) {
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(frameId, fragment);
    transaction.commit();
}
 
Example 20
Source File: FragmentEventReceiver.java    From pandroid with Apache License 2.0 4 votes vote down vote up
@Override
protected void onOpenerReceived(FragmentOpener fragmentOpener) {

    if (clearBackStack) {
        clearBackStack();
    }


    Fragment fragment = getFragment(fragmentOpener);
    if (fragment == null) {
        return;
    }

    T attachedObject = refAttachedObject.get();

    if (attachedObject == null) {
        return;
    }


    FragmentTransaction trans = ((T) attachedObject).provideFragmentManager().beginTransaction();
    if (anim != null && anim.length > 3)
        trans.setCustomAnimations(anim[0], anim[1], anim[2], anim[3]);

    if (backStackTag != null) {
        trans.addToBackStack(backStackTag);
    }

    if (fragmentOpener.getTitle() != null) {
        trans.setBreadCrumbTitle(fragmentOpener.getTitle());
    } else if (defaultBreadcrumbTitle != null) {
        trans.setBreadCrumbTitle(defaultBreadcrumbTitle);
    }

    boolean handled = onExecuteFragmentTransaction(fragmentOpener, fragment, trans);
    if (!handled) {
        if (fragment instanceof DialogFragment) {
            ((DialogFragment) fragment).show(trans, fragmentTag);
        } else {
            trans.replace(fragmentContainerId, fragment, fragmentTag);
            try {
                trans.commit();
            } catch (IllegalStateException e) {
                Log.w(TAG, "Commit failed", e);
            }
        }
    }


}