What id to put in fragmentTransaction.replace() method argument?

user3904345 picture user3904345 · Aug 22, 2014 · Viewed 10.8k times · Source

I am trying to call fragment from fragment.

I am using following code:

Fragment fragment = new TeamDetails3();

                FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
                fragmentTransaction.replace(R.id.frame_container, fragment);
                fragmentTransaction.commit();

My current fragment layout is team_details3.xml and the fragment which i am calling has layout team_details4.xml. I also tried putting

fragmentTransaction.replace(R.id.team_details4, fragment);
fragmentTransaction.replace(R.id.team_details3, fragment);

but they show error

I am getting these errors if i put fragmentTransaction.replace(R.id.frame_container, fragment)-

No view found for id 0x7f080159 (com.pepup.league:id/frame_container) for fragment TeamDetails3{41916708 #1 id=0x7f080159}
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:930)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
            at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:153)
            at android.app.ActivityThread.main(ActivityThread.java:5086)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
            at dalvik.system.NativeStart.main(Native Method)
08-22 12:07:49.420      347-363/? E/AppErrorDialog﹕ Failed to get ILowStorageHandle instance

Answer

Rod_Algonquin picture Rod_Algonquin · Aug 22, 2014

You only need to use one layout id for changing fragment as the layout in fragment managers

You can use this id android.R.id.content as the main layout for changing the fragments