Example usage for android.app FragmentTransaction replace

List of usage examples for android.app FragmentTransaction replace

Introduction

In this page you can find the example usage for android.app FragmentTransaction replace.

Prototype

public abstract FragmentTransaction replace(@IdRes int containerViewId, Fragment fragment);

Source Link

Document

Calls #replace(int,Fragment,String) with a null tag.

Usage

From source file:com.TurnOrder.MainActivity.java

private void changeNavItem(int position, Player p) {
    Fragment fragment = null;//from ww  w .j a va 2  s .  co  m
    switch (position + 1) {
    case 1:
        fragment = new FragmentHome();
        setTitleMenu(titlemenue, "Home");

        break;
    case 2:
        fragment = new FragmentAddPlayer();
        setTitleMenu(titlemenue, "Add Player");
        break;
    case 3:
        fragment = new FragmentViewPlayer(p, playerList);
        setTitleMenu(titlemenue, "View Player");
        break;
    case 4:
        fragment = new FragmentPlay(playerList);
        setTitleMenu(titlemenue, "Play");
        break;
    case 5:
        fragment = new FragmentSplash();
        setTitleMenu(titlemenue, "Savage Worlds Licence");
    }

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    fragmentTransaction.replace(R.id.container, fragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commitAllowingStateLoss();
}

From source file:com.folio3.parse.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ParseAnalytics.trackAppOpenedInBackground(getIntent());

    String filePath = getApplicationContext().getFilesDir().getPath().toString() + "/" + FILE;
    File file = new File(filePath);
    try {//from  w ww. ja v  a  2 s  .  c om
        if (!file.exists()) {
            System.out.println("Creating new file");
            file.createNewFile();
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }

    /** When push message is clicked onCreate function of this activity is called */
    Bundle extras = getIntent().getExtras();
    if (extras != null && extras.getString(KEY_PUSH_DATA) != null) {

        JSONObject pushData = null;
        try {
            pushData = new JSONObject(extras.getString(KEY_PUSH_DATA));
        } catch (JSONException e) {
            Log.e(TAG, "Unexpected JSONException when receiving push data: ", e);
        }

        String alert = null;
        if (pushData != null) {
            alert = pushData.optString("alert", null);
        }

        // Write log to the logfile
        if (alert != null) {
            writeLogToFile(getApplicationContext(), alert);
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            Fragment pushFragment = new PushFragment();
            ft.replace(R.id.push_fragment, pushFragment);
            ft.commit();
        }
    }

}

From source file:com.google.samples.apps.abelana.BaseActivity.java

private void selectItem(int position) {
    FragmentManager fragmentManager = getFragmentManager();

    if (position == NAVDRAWER_ITEM_SETTINGS) {
        Intent intent = new Intent(getApplicationContext(), SettingsActivity.class);
        startActivity(intent);//ww w . j  a va  2 s  .  c o m
    }
    if (position == NAVDRAWER_ITEM_FOLLOWING) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.content_frame, new FriendsFragment()).commit();
    }
    if (position == NAVDRAWER_ITEM_HOME) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.content_frame, new FeedFragment()).commit();
    }
    if (position == NAVDRAWER_ITEM_PROFILE) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.content_frame, new ProfileFragment()).commit();
    }

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

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

private void insertFragment(Fragment fragment, Bundle args) {
    fragment.setArguments(args);/*  ww w  . j a  v a2s  . co m*/
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.content_frame, fragment).commit();
}

From source file:cn.androidy.swiftlib.navigationdrawer.NavigationDrawerActivity.java

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

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.replace(R.id.content_frame, fragment);
    ft.commit();/*from ww  w.  j  ava  2  s.  c  o  m*/

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

From source file:com.example.android.adrenaland.MainActivity.java

public void selectItemSeeRidePin(boolean cloud, boolean bigDrop) {
    Fragment fragment = new FragmentNavigation();
    Bundle args = new Bundle();
    args.putBoolean(FragmentNavigation.ARG_CLOUD, cloud);
    args.putBoolean(FragmentNavigation.ARG_BIG_DROP, bigDrop);
    fragment.setArguments(args);//from   w w w  .ja  v  a2 s .c om
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();

    ft.replace(R.id.content_frame, fragment).commit();

    mDrawerList.setItemChecked(1, true);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.android.messaging.ui.appsettings.ApplicationSettingsActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    final boolean topLevel = getIntent().getBooleanExtra(UIIntents.UI_INTENT_EXTRA_TOP_LEVEL_SETTINGS, false);
    if (topLevel) {
        getSupportActionBar().setTitle(getString(R.string.settings_activity_title));
    }//from   w ww.  ja v a  2 s  .  co  m

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(android.R.id.content, new ApplicationSettingsFragment());
    ft.commit();
}

From source file:com.sharklee.navigationDrawer.MainActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new PlanetFragment();
    Bundle args = new Bundle();
    args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
    //??PlanetFragment?
    fragment.setArguments(args);/*  ww  w  .j  a v  a 2  s  .  com*/
    //PlanetFragment?FrameLayout??
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.content_frame, fragment);
    fragmentTransaction.addToBackStack("");
    fragmentTransaction.commit();

    // update selected item and title, then close the drawer
    //MainActivityposition=0?ListView?ListView?ListView?position=0
    mDrawerList.setItemChecked(position, true);
    setTitle(mPlanetTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.filemanager.free.activities.Preferences.java

public void selectItem(int i) {
    switch (i) {//from   w  w w  .  ja va2  s  .  c o m
    case 0:
        p = new Preffrag();
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.prefsfragment, p);
        transaction.commit();
        select = 0;
        assert (getSupportActionBar()) != null;
        getSupportActionBar().setTitle(R.string.setting);
        break;
    default:
        break;
    }
}

From source file:com.twp.music.LocalMusicActivity.java

private void checkedPage(LocalType type) {
    Fragment f = null;//  w w w. java2 s .  co  m
    showType = type;
    switch (type) {
    case ALLMUSIC:
        int count = getIntent().getIntExtra("MusicCount", 0);
        f = LocalAllMusicFragment.newInstance(count);
        break;
    case ARTISTBROWSE:
        f = LocalArtistFragment.newInstance();
        break;
    case DIRBROWSE:
        f = LocalFileFragment.newInstance();
        break;
    }
    if (null != f) {
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.content, f);
        ft.commit();
    } else {
        Logger.w("not find LocalType ,");
    }
}