minci
minci

Reputation: 3

FragmentManager with FragmentTabHost

I have an Activity that has a ViewPager with four Fragments. One of those Fragments must have two tabs inside of it so I tried FragmentTabHost.

private FragmentTabHost fragmentTabHost;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_zbritjet, container, false);
    fragmentTabHost = (FragmentTabHost) view.findViewById(android.R.id.tabhost);
    fragmentTabHost.setup(view.getContext(), getFragmentManager(), android.R.id.tabcontent);

    fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tab_ofertat").setIndicator("Ofertat"), OfertatItems.class, null);
    fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tab_bizneset").setIndicator("Bizneset"), BiznesetItems.class, null);
    return view;
}

The problem is that android is throwing

java.lang.IllegalStateException: FragmentManager is already executing transactions

Stack trace:

android.support.v4.app.FragmentManagerImpl.ensureExecReady(FragmentManager.java:1946) android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1992) android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:762) android.support.v4.app.FragmentTabHost.onAttachedToWindow(FragmentTabHost.java:289)

Upvotes: 0

Views: 313

Answers (1)

Hristo Stoyanov
Hristo Stoyanov

Reputation: 1960

Try getChildFragmentManager() instead of getFragmentManager().

From the docs:

Return a private FragmentManager for placing and managing Fragments inside of this Fragment.

Upvotes: 1

Related Questions