FragmentTransaction not showing replaced fragment

2.6k views Asked by At

After replacing the my fragment container in the main view with a new instance of another fragment class, nothing seems to be happening

 case 2:
        Log.d("Menu", "Sent clicked");
        try {
            android.support.v4.app.Fragment fragment = new SentFragment();
            FragmentTransaction fm = getSupportFragmentManager().beginTransaction();
            fm.replace(R.id.frameLayout, fragment);
            fm.commit();
            getSupportFragmentManager().executePendingTransactions();
        }catch(Exception e){
            e.printStackTrace();
        }
        break;

and my Logcat is something like this

    06-19 09:12:29.487  19458-19458/com.pacentltd.mail D/Menu﹕ Sent clicked
    06-19 09:12:29.487  19458-19458/com.pacentltd.mail D/Frag﹕ Attached

after calling onAttach on the fragment it self

1

There are 1 answers

1
Meenaxi On

check modifications below

case 2:
    Log.d("Menu", "Sent clicked");
    try {
        SentFragment fragment = new SentFragment(); // updated line
        FragmentTransaction fm = getSupportFragmentManager().beginTransaction();
        fm.replace(R.id.frameLayout, fragment);
        fm.commit();
        getSupportFragmentManager().executePendingTransactions();
    }catch(Exception e){
        e.printStackTrace();
    }
    break;

create instance of SentFragment and not of android.support.v4.app.Fragment. And also make sure your SentFragment class extends android.support.v4.app.Fragment