Reputation:
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
Upvotes: 3
Views: 12172
Reputation: 3596
This is how I do it. Hope it helps
//calling the next fragment. i have written it in another class which extends Fragment
//ContactsFragment is the fragment that I am calling
ContactsFragment mContactsFragment = new ContactsFragment();
FragmentTransaction transaction = fragManager.beginTransaction();
//here default layout is a linear layout in the xml file of this activity
transaction.replace(R.id.defaultLayout,new ContactsFragment());
transaction.commit();
Basically in transaction.replace()
the first parameter will be the id of the layout in which you want to place your fragment. And the second parameter should be the fragment.
Upvotes: 0
Reputation: 26198
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
Upvotes: 3
Reputation: 8558
This is the link to the developers site. FragmentTransaction.replace
Like it mentions, the id needs to be the id of the container where you need to place this fragment. Since you began with android.R.id.content
, I'm guessing that is what you need to
pass, unless there is other code that isn't included in the question.
Upvotes: 0
Reputation: 588
try below code
FragmentTransaction fragmentTransition = getFragmentManager().beginTransaction();
TeamDetails3 fragmentClass = new TeamDetails3 ();
fragmentTransition.replace(R.id.realtabcontent, fragmentClass ,"");
fragmentTransition.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
fragmentTransition.addToBackStack(fragmentClass .getClass().getName());
fragmentTransition.commit();
Upvotes: 0
Reputation: 2438
Try this. I guess it should work
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment_container, fragmentB, tag);
ft.addToBackStack(null);
ft.commit();
Upvotes: 0