2017-03-09 108 views
0

我有一個有四個片段ViewPager的活動。其中一個片段必須有兩個標籤,所以我嘗試了FragmentTabHost。片段管理器與片段TabHost

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; 
} 

的問題是,Android是扔

java.lang.IllegalStateException:FragmentManager已執行交易

堆棧跟蹤:

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)

回答

1

嘗試getChildFragmentManager()而不是getFragmentManager()

從文檔:

返回用於放置和管理這個片段的片段中的私有FragmentManager。