Android: tabhost in snippet, w / snippets as tabs

as indicated in the header, I am trying to have the tabhost that it contains in the fragment, where the contents of the tab are determined by the fragments. then,

i started with an example of FragmentsTab from Google. this shows how to use snippets as the contents of the tab, but TabHost itself is still hosted in action. again, I need the tab host to be in the fragment.

I took the FragmentsTab example and moved the code to onCreate() and moved it to onCreateView() in my Fragment ,

 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View fragmentView = inflater.inflate(R.layout.detail_fragment, container); mTabHost = (TabHost) fragmentView.findViewById(android.R.id.tabhost); mTabHost.setup(); mTabManager = new TabManager(getActivity(), mTabHost, R.id.realtabcontent); // TODO: localize mTabManager.addTab(mTabHost.newTabSpec("info").setIndicator("File Info"), InfoFragment.class, null); return fragmentView; } 

when I run, I get this exception,

 05-25 14:42:27.272: E/AndroidRuntime(4701): Caused by: java.lang.IllegalStateException: Recursive entry to executePendingTransactions 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1343) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:429) 05-25 14:42:27.272: E/AndroidRuntime(4701): at com.zimbra.octopus.android.TabManager.onTabChanged(TabManager.java:116) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.widget.TabHost.invokeOnTabChangeListener(TabHost.java:359) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.widget.TabHost.setCurrentTab(TabHost.java:344) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.widget.TabHost.addTab(TabHost.java:216) 05-25 14:42:27.272: E/AndroidRuntime(4701): at com.zimbra.octopus.android.TabManager.addTab(TabManager.java:92) 05-25 14:42:27.272: E/AndroidRuntime(4701): at com.zimbra.octopus.android.DetailFragment.onCreateView(DetailFragment.java:46) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:819) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1053) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1371) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:429) 05-25 14:42:27.272: E/AndroidRuntime(4701): at com.zimbra.octopus.android.TabManager.onTabChanged(TabManager.java:116) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.widget.TabHost.invokeOnTabChangeListener(TabHost.java:359) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.widget.TabHost.setCurrentTab(TabHost.java:344) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.widget.TabHost.addTab(TabHost.java:216) 05-25 14:42:27.272: E/AndroidRuntime(4701): at com.zimbra.octopus.android.TabManager.addTab(TabManager.java:92) 05-25 14:42:27.272: E/AndroidRuntime(4701): at com.zimbra.octopus.android.DetailFragment.onCreateView(DetailFragment.java:46) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:819) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1032) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1111) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:264) 05-25 14:42:27.272: E/AndroidRuntime(4701): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) 

looking at the trace, I see onCreateView() for DetailFragment (fragment accepting TabHost ), recursively. one way or another, a call to TabManager.addTab() (again, see the FragmentsTab example) leads to a recursive call to DetailFragment.onCreateView() .

what am I doing wrong? is it even possible? thanks.

+4
source share
2 answers

Android does not allow you to insert some fragments inside other fragments. Your logarithm indicates that you are executing one fragment transaction in another (i.e., a Recursive record to executePendingTransactions). It's just not allowed, sorry!

+2
source

add this before setting up TabHost:

 LocalActivityManager mLocalActivityManager = new LocalActivityManager(getActivity(), false); mLocalActivityManager.dispatchCreate(savedInstanceState); mTabHost.setup(mLocalActivityManager); 
0
source

Source: https://habr.com/ru/post/1414465/


All Articles