Example usage for android.support.v4.app FragmentTransaction add

List of usage examples for android.support.v4.app FragmentTransaction add

Introduction

In this page you can find the example usage for android.support.v4.app FragmentTransaction add.

Prototype

public abstract FragmentTransaction add(int containerViewId, Fragment fragment, String tag);

Source Link

Document

Add a fragment to the activity state.

Usage

From source file:com.amsterdam.marktbureau.makkelijkemarkt.NotitiesActivity.java

/**
 *
 * @param savedInstanceState//from  w w w  .j a v a  2 s .  c o m
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // get selected markt naam from sharedpreferences
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    String marktNaam = settings.getString(getString(R.string.sharedpreferences_key_markt_naam), "");

    // set the title and subtitle in the toolbar
    setToolbarTitle(getString(R.string.notities));
    setToolbarSubtitle(marktNaam);

    // add the about fragment to the container
    if (savedInstanceState == null) {
        mNotitiesFragment = new NotitiesFragment();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.container, mNotitiesFragment, NOTITIES_FRAGMENT_TAG);
        transaction.commit();
    } else {
        mNotitiesFragment = (NotitiesFragment) getSupportFragmentManager()
                .findFragmentByTag(NOTITIES_FRAGMENT_TAG);
    }

    // set the active drawer menu option
    if (mDrawerFragment.isAdded()) {
        mDrawerFragment.checkItem(mDrawerFragment.DRAWER_POSITION_NOTITIES);
    }
}

From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningenActivity.java

/**
 *
 * @param savedInstanceState/*from  www.j a  v  a 2  s . c om*/
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // get selected markt naam from sharedpreferences
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    String marktNaam = settings.getString(getString(R.string.sharedpreferences_key_markt_naam), "");

    // set the title and subtitle in the toolbar
    setToolbarTitle(getString(R.string.dagvergunningen));
    setToolbarSubtitle(marktNaam);

    // add the about fragment to the container
    if (savedInstanceState == null) {
        mDagvergunningenFragment = new DagvergunningenFragment();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.container, mDagvergunningenFragment, DAGVERGUNNINGEN_FRAGMENT_TAG);
        transaction.commit();
    } else {
        mDagvergunningenFragment = (DagvergunningenFragment) getSupportFragmentManager()
                .findFragmentByTag(DAGVERGUNNINGEN_FRAGMENT_TAG);
    }

    // set the active drawer menu option
    if (mDrawerFragment.isAdded()) {
        mDrawerFragment.checkItem(mDrawerFragment.DRAWER_POSITION_DAGVERGUNNINGEN);
    }
}

From source file:com.amsterdam.marktbureau.makkelijkemarkt.AboutPublicActivity.java

/**
 * Set the about_activity layout and add the aboutfragment
 * @param savedInstanceState Bundle//from ww  w  .  java 2 s  . co m
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // set the layout
    setContentView(R.layout.about_activity);

    // bind the elements to the view
    ButterKnife.bind(this);

    // set the toolbar as supportactionbar, with default title disabled and homebutton enabled
    setSupportActionBar(mToolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        // set the title in the toolbar
        mTitleView.setText(R.string.about);
    }

    // create new or get existing instance of aboutfragment
    if (savedInstanceState == null) {
        mAboutFragment = new AboutFragment();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.container, mAboutFragment, ABOUT_FRAGMENT_TAG);
        transaction.commit();
    } else {
        mAboutFragment = (AboutFragment) getSupportFragmentManager().findFragmentByTag(ABOUT_FRAGMENT_TAG);
    }
}

From source file:com.fbbackup.FriendAlbumListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (BuildConfig.DEBUG) {
        Utils.enableStrictMode();//  w ww .  ja v a  2  s  .co m
    }
    super.onCreate(savedInstanceState);

    albumArray = getIntent().getExtras().getStringArray("albumArray");
    albumCoverArray = getIntent().getExtras().getStringArray("albumCoverArray");
    albumCoverUrlArray = getIntent().getExtras().getStringArray("albumCoverUrlArray");
    albumNameArray = getIntent().getExtras().getStringArray("albumNameArray");
    albumPhotoAccountArray = getIntent().getExtras().getStringArray("albumPhotoAccountArray");
    token = getIntent().getExtras().getString("token");
    name = getIntent().getExtras().getString("userName");

    if (getSupportFragmentManager().findFragmentByTag(TAG) == null) {

        Fragment newFragment = new FriendAlbumList();

        Bundle args = new Bundle();

        args.putStringArray("albumArray", albumArray);
        args.putStringArray("albumCoverArray", albumCoverArray);
        args.putStringArray("albumCoverUrlArray", albumCoverUrlArray);
        args.putStringArray("albumNameArray", albumNameArray);
        args.putStringArray("albumPhotoAccountArray", albumPhotoAccountArray);
        args.putString("token", token);
        args.putString("userName", name);

        newFragment.setArguments(args);

        final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

        ft.add(android.R.id.content, newFragment, TAG);
        ft.commit();
    }
}

From source file:com.fbbackup.ImageGridActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (BuildConfig.DEBUG) {
        Utils.enableStrictMode();//  www .j  a  v a  2  s  . com
    }
    super.onCreate(savedInstanceState);

    photoArray = getIntent().getExtras().getStringArray("albumPhoto");

    albumName = getIntent().getExtras().getString("albumName");

    name = getIntent().getExtras().getString("userName");

    for (int i = 0; i < photoArray.length; i++) {
        Log.w("photo", i + ":" + photoArray[i]);
    }

    if (getSupportFragmentManager().findFragmentByTag(TAG) == null) {

        Fragment newFragment = new ImageGridFragment();

        Bundle args = new Bundle();

        args.putStringArray("photo", photoArray);

        args.putString("albumName", albumName);

        args.putString("userName", name);

        Log.w("downloadpic", "ImageGridActivity albumName:" + albumName);

        newFragment.setArguments(args);

        final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

        ft.add(android.R.id.content, newFragment, TAG);
        ft.commit();
    }
}

From source file:com.cyrilmottier.android.polaris2demo.ProgrammaticDemoActivity.java

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

    // It isn't possible to set a fragment's id programmatically so we set a tag instead and
    // search for it using that.
    mMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByTag(MAP_FRAGMENT_TAG);

    // We only create a fragment if it doesn't already exist.
    if (mMapFragment == null) {
        // To programmatically add the map, we first create a SupportMapFragment.
        mMapFragment = SupportMapFragment.newInstance();

        // Then we add it using a FragmentTransaction.
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.add(android.R.id.content, mMapFragment, MAP_FRAGMENT_TAG);
        fragmentTransaction.commit();/*  w w  w. j av a  2 s  .com*/
    }

    // We can't be guaranteed that the map is available because Google Play services might
    // not be available.
    setUpMapIfNeeded();
}

From source file:com.amsterdam.marktbureau.makkelijkemarkt.NotitieActivity.java

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

    // set the title in the toolbar
    Intent intent = getIntent();//from  ww  w  .ja v a 2  s .  c  o m
    if ((intent != null) && (intent
            .hasExtra(MakkelijkeMarktProvider.mTableNotitie + MakkelijkeMarktProvider.Notitie.COL_ID))) {
        setToolbarTitle(getString(R.string.notitie_edit));
    } else {
        setToolbarTitle(getString(R.string.notitie_add));
    }

    // get selected markt naam from sharedpreferences and set the subtitle in the toolbar
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    String marktNaam = settings.getString(getString(R.string.sharedpreferences_key_markt_naam), "");
    setToolbarSubtitle(marktNaam);

    // create new or get existing instance of notitiefragment
    if (savedInstanceState == null) {
        mNotitieFragment = new NotitieFragment();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.container, mNotitieFragment, NOTITIE_FRAGMENT_TAG);
        transaction.commit();
    } else {
        mNotitieFragment = (NotitieFragment) getSupportFragmentManager()
                .findFragmentByTag(NOTITIE_FRAGMENT_TAG);
    }

    // set the active drawer menu option
    if (mDrawerFragment.isAdded()) {
        mDrawerFragment.checkItem(mDrawerFragment.DRAWER_POSITION_NOTITIES);
    }

    // replace the drawer hamburger with the back-arrow
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        mDrawerToggle.setDrawerIndicatorEnabled(false);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
}

From source file:com.agna.setmaster.ui.screen.main.MainActivity.java

protected void addFragment(int containerViewId, android.support.v4.app.Fragment fragment, String tag) {
    android.support.v4.app.FragmentTransaction fragmentTransaction = this.getSupportFragmentManager()
            .beginTransaction();//  ww w  .j av  a 2s  .c om
    fragmentTransaction.add(containerViewId, fragment, tag);
    fragmentTransaction.commit();
}

From source file:com.fragmentmaster.sample.ReceiveResult.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mResultView = (TextView) view.findViewById(R.id.resultView);
    view.findViewById(R.id.button).setOnClickListener(new OnClickListener() {
        @Override//from  w ww. j a va 2  s  .  co  m
        public void onClick(View v) {
            startFragmentForResult(NumbersList.class, REQUEST_CODE);
        }
    });
    FragmentManager fragmentManager = getChildFragmentManager();
    if (fragmentManager.findFragmentByTag("TAG_CHILD") == null) {
        FragmentTransaction ft = fragmentManager.beginTransaction();
        ft.add(R.id.childContainer, new Child(), "TAG_CHILD");
        ft.commitAllowingStateLoss();
        fragmentManager.executePendingTransactions();
    }
}

From source file:com.example.android.bitmapfun.ui.SearchStreamGridActivity.java

private void showResults(ConnexusStream.List streams) {
    ConnexusStream.List selectedStreams = new ConnexusStream.List();

    if (searchCriteria != null) {
        //Collections.sort(streams);
        int i = 0;
        for (ConnexusStream s : streams) {
            if (s.name.contains(searchCriteria) || s.tags.contains(searchCriteria)) {
                selectedStreams.add(s);/*from ww w .j  av a2s. c o  m*/
            }
        }
    } else {
        selectedStreams = streams;
    }

    if (getSupportFragmentManager().findFragmentByTag(TAG) == null) {
        final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.add(android.R.id.content,
                SearchStreamGridFragment.newInstance((ConnexusStream.List) selectedStreams, searchCriteria),
                TAG);
        ft.commit();
    }
}