简体   繁体   中英

How i can use .replace(Fragment , mapsFragment)? Android

I have use .replace() for replace a old Fragment with a new, but in this moment i do no how use the same of .replace() by a Fragment to a mapsFragment.

Ideas?! I can use replace? if i can' t use it, what I can use?

This is my code in this moment. (the .replace() don' t work)

public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments
    FragmentManager fragmentManager = getFragmentManager();
    mapsFragment fragM = null;
    Fragment frag = null;
    switch (position) {
        case 0: //Home
            mTitle = "Maps";
            fragM = new mapsFragment();
            break;

        case 1: //Query utente
            mTitle = "Section 2";
            break;

        case 2: //Query Amministratore
            mTitle = "Section 3";
            break;
    }

    if (position != 3) {
        if(position==0){
            fragmentManager.beginTransaction()
                    .replace(R.id.container, fragM)
                    .commit();
        }else {
            fragmentManager.beginTransaction()
                    .replace(R.id.container, frag)
                    .commit();
        }

I have find the solution: link where i have found it

This is the code in particular:

if(position==0){
            FragmentTransaction mTransaction = getSupportFragmentManager()
                    .beginTransaction();
            SupportMapFragment mFRaFragment = new mapsFragment();
            mTransaction.replace(R.id.container, mFRaFragment);
            mTransaction.commit();
        }else {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM