【问题标题】:To display another fragment from a fragmentwrapper显示来自片段包装器的另一个片段
【发布时间】:2015-07-13 18:22:38
【问题描述】:

我有一个自定义的 FragmentWrapper 类,我每次都想从中返回一个新实例。

但在其中,我不想在每个实例中显示另一个 Singleton Fragment

SingletonFragment 中应该有一个 single fragment。 而且,FragmentWrapper 的所有实例都应该显示 Singleton fragment.

我尝试使用nested fragmentfragmentchildmanager,但它不起作用。

下面是代码:

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View root = inflater.inflate(R.layout.xxxlayout, container, false);

    getChildFragmentManager().beginTransaction()

            .replace(R.id.xxxcontainer, singletonfragment)

            .commit();

    return root;

}

请提出建议。

【问题讨论】:

    标签: android-nested-fragment


    【解决方案1】:

    提交后添加以下行

    getChildFragmentManager().executePendingTransactions();
    

    像这样:

    @Override
    
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
        final View root = inflater.inflate(R.layout.xxxlayout, container, false);
    
        getChildFragmentManager().beginTransaction()
    
                .replace(R.id.xxxcontainer, singletonfragment)
    
                .commit();
        getChildFragmentManager().executePendingTransactions();
        return root;
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-14
      • 1970-01-01
      相关资源
      最近更新 更多