我试图从片段中调用片段。
我正在使用以下代码:
Fragment fragment = new TeamDetails3();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.frame_container, fragment);
fragmentTransaction.commit();
我当前的片段布局是team_details3.xml
,我正在调用的片段有布局team_details4.xml
。我也尝试过把
fragmentTransaction.replace(R.id.team_details4, fragment);
fragmentTransaction.replace(R.id.team_details3, fragment);
但他们显示错误
如果我放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
答案 0 :(得分:2)
您只需使用一个布局ID将片段更改为片段管理器中的布局
您可以使用此ID android.R.id.content
作为更改片段的主要布局
答案 1 :(得分:0)
试试这个。我想它应该可行
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment_container, fragmentB, tag);
ft.addToBackStack(null);
ft.commit();
答案 2 :(得分:0)
我就是这样做的。希望它有所帮助
//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();
基本上在transaction.replace()
中,第一个参数将是您要放置片段的布局的ID。第二个参数应该是片段。
答案 3 :(得分:0)
尝试以下代码
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();
答案 4 :(得分:0)
这是开发者网站的链接。 FragmentTransaction.replace
就像它提到的那样,id需要是你需要放置这个片段的容器的id。自从android.R.id.content
开始,我猜这就是你需要的
传递,除非有其他代码未包含在问题中。