Example usage for android.app FragmentManager beginTransaction

List of usage examples for android.app FragmentManager beginTransaction

Introduction

In this page you can find the example usage for android.app FragmentManager beginTransaction.

Prototype

public abstract FragmentTransaction beginTransaction();

Source Link

Document

Start a series of edit operations on the Fragments associated with this FragmentManager.

Usage

From source file:at.flack.MainActivity.java

public boolean facebookLogin(String mail, String password) {
    try {//from  w  w  w. ja  v a 2 s.com
        if (!new FacebookLoginTask().execute(mail, password).get()) {
            return false;
        }
    } catch (InterruptedException e) {
        return false;
    } catch (ExecutionException e) {
        return false;
    }
    redrawFbFragment();
    facebookLogin();
    FacebookMainActivity.forceReinstance();
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, FacebookMainActivity.getInstance()).commit();

    return true;
}

From source file:com.neighbor.ex.tong.ui.activity.MainActivity2Activity.java

public void selectItem(int possition) {

    FragmentManager fragmentManager = getFragmentManager();
    Bundle args = new Bundle();
    switch (possition) {

    case Common.MENU_HOME:
        fragment = new TongFragment();
        fragment.setArguments(args);/*  w ww . j ava2  s.c om*/
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
        break;
    case Common.MENU_LIFE_LOG:
        //                fragment = new GroupTongFragment();
        fragment = new GroupTongFragment_test();
        fragment.setArguments(args);
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
        break;
    case Common.MENU_ACTIVITY:
        fragment = new SettingFragment();
        fragment.setArguments(args);
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
        break;
    case Common.MENU_NOTICE:
        fragment = new MapFragment();
        fragment.setArguments(args);
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
        break;
    case Common.MENU_SLEEP:
        fragment = new MessageBoxFragment();
        fragment.setArguments(args);
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
        break;

    default:
        break;
    }
    fragmentIdx = possition;
    setTitle(getResources().getStringArray(R.array.menu_array)[possition]);
    mDrawerLayout.closeDrawer(drawerView);
}

From source file:org.akvo.caddisfly.ui.activity.MainActivity.java

void displayView(int position, boolean addToBackStack) {
    int index = getCurrentFragmentIndex();

    if (index == position) {
        // requested fragment is already showing
        return;// w ww.  j  a va2 s. c o  m
    }

    MainApp mainApp = (MainApp) getApplicationContext();

    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    if (Config.FLOW_ACTION_EXTERNAL_SOURCE.equals(action) && type != null) {
        if ("text/plain".equals(type)) { //NON-NLS
            external = true;
            //mQuestionId = getIntent().getStringExtra("questionId");
            mQuestionTitle = getIntent().getStringExtra("questionTitle");

            String code = mQuestionTitle.substring(Math.max(0, mQuestionTitle.length() - 5));

            mainApp.setSwatches(code);
        }
    }

    if (mainApp.currentTestInfo == null) {
        mainApp.currentTestInfo = new TestInfo("", "", "");
    }

    Fragment fragment;

    switch (position) {
    case Config.HOME_SCREEN_INDEX:
        mStartFragment = StartFragment.newInstance(external, mainApp.currentTestInfo.getCode());
        fragment = mStartFragment;
        break;
    case Config.CALIBRATE_SCREEN_INDEX:
        mCalibrateFragment = new CalibrateFragment();
        fragment = mCalibrateFragment;
        setupActionBarSpinner();

        break;
    case Config.SETTINGS_SCREEN_INDEX:
        if (mSettingsFragment == null) {
            mSettingsFragment = new SettingsFragment();
        }
        fragment = mSettingsFragment;
        break;
    default:
        return;
    }
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.replace(R.id.container, fragment, String.valueOf(position));
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    if (addToBackStack) {
        ft.addToBackStack(null);
    }
    ft.commit();

    invalidateOptionsMenu();
    updateActionBarNavigation(position);
}

From source file:com.hit.jj.mapshow.RoutingActivity.java

@Override
public void onDialogRouteClicked(Point p1, Point p2) {
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.remove(fm.findFragmentByTag("Dialog")).commit();

    pathfind(p1, p2);/*from  ww  w  .  j a  v a  2 s. c  om*/

}

From source file:com.hit.jj.mapshow.RoutingActivity.java

@Override
public void onDialogRouteClicked(Point p) {
    //        Point s1 = new Point(26.0734997,119.3150024);
    Point s1 = new Point(26.1023006, 119.2789993);
    Point s2 = new Point(mLocation.getY(), mLocation.getX());
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.remove(fm.findFragmentByTag("SpeakDialog")).commit();
    pathfind(s2, p);//
    //pathfind(s1, p);//
}

From source file:cw.kop.autobackground.sources.SourceInfoFragment.java

private void showAlbumFragment(String type, int position, ArrayList<String> names, ArrayList<String> images,
        ArrayList<String> links, ArrayList<String> nums, boolean use) {
    AlbumFragment albumFragment = new AlbumFragment();
    Bundle arguments = new Bundle();
    arguments.putString("type", type);
    arguments.putInt("position", position);
    arguments.putBoolean("use", use);
    arguments.putStringArrayList("album_names", names);
    arguments.putStringArrayList("album_images", images);
    arguments.putStringArrayList("album_links", links);
    arguments.putStringArrayList("album_nums", nums);
    albumFragment.setArguments(arguments);
    albumFragment.setTargetFragment(this, -1);

    FragmentManager fragmentManager = getFragmentManager();

    if (fragmentManager != null) {
        fragmentManager.beginTransaction().add(R.id.content_frame, albumFragment, "album_fragment")
                .addToBackStack(null).commit();
    }/* ww  w .  j  a  v a  2s.  c om*/
}

From source file:com.hit.jj.mapshow.RoutingActivity.java

@Override
public void onSegmentSelected(String id) {

    if (id == null)
        return;//from   w  w  w  .  j  av a 2 s.c o  m
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.remove(fm.findFragmentByTag("Nav Drawer")).commit();
    clearAll();
    // Look for the graphic that corresponds to this direction
    removeRoad(mPaths, id);
    new Handler().post(new Runnable() {
        @Override
        public void run() {
            updateUI();
        }
    });
}

From source file:com.dsna.android.main.MainActivity.java

private void openFragment(BaseFragment baseFragment) {
    if (baseFragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        fragmentTransaction.replace(R.id.fragment_main, baseFragment);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();/*w  ww  .j a  v a  2 s .c  o m*/
        if (baseFragment.getTitleResourceId() > 0)
            mCurrentTitle = baseFragment.getTitleResourceId();

    }
}

From source file:de.marcelkapfer.morseconverter.MainActivity.java

public void changeFragment(int position) {

    fragment_main newFragment = new fragment_main();
    Bundle args = new Bundle();
    args.putInt(fragments[position], position);
    newFragment.setArguments(args);/*from w w w  .  j a v a2s.c  o  m*/

    // Insert the fragment by replacing any existing fragment
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.container, newFragment).commit();

    mDrawerList.setItemChecked(position, true);
    setTitle(mMenuTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);

}

From source file:com.google.cloud.solutions.cloudadventure.GameActivity.java

/**
 * Shows the {@link PreGameFragment} game lobby screen and creates a new {@link Player}. This
 * method is called almost immediately, within the Activity's onCreate().
 *//*w w w.ja  va2s . c o m*/
private void joinGame() {
    // Show the pre-game lobby screen
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    mPreGameFragment = new PreGameFragment();
    fragmentTransaction.add(R.id.game_activity, mPreGameFragment);
    fragmentTransaction.commit();

    new JoinGame().execute(mGameId, mHandle);
}