我们可以在视图分页器的一个父片段中嵌套两个子片段吗? [英] Can we nested two child fragment inside one parent fragment in view pager?
问题描述
我有一个视图分页器,在选项卡之一中,我有一个父片段,其中包含两个子片段.
I have a view pager,in one of tab I have parent fragment which contained two child fragment.
候选列表是具有框架容器的父片段,我在其中替换了一个子容器( candidatelistfragment ),但是当我替换了另一个子容器(候选事件开始)时,它说找不到视图.
Candidatelist is the parent fragment which had a frame container I replace one child(candidatelistfragment) inside that container but when I replace one more child(candidate event start) inside it it says view not found.
我用来替换父片段容器中的第一个孩子的代码是(这很好)
Code I am using to replace the first child inside the parent fragment container is (this works well)
Fragment childFragment = new CandidateListFragment();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.replace(R.id.childContainer, childFragment,"listfragment").commit();
现在,当我必须在其中添加一个子容器时,childContainer是父容器的ID,它说未找到视图.
Here childContainer is the parent container's ID now when I have to add one more child inside it it says view not found.
Fragment childFragment = new CandidateStartEvent();
FragmentTransaction transaction =getChildFragmentManager().beginTransaction();
transaction.replace(R.id.childContainer, childFragment).commit();
推荐答案
我已经解决了我使用getFragmentManager的第二个子片段上发布的问题
I have resolved the issued on the second child fragment I used getFragmentManager
CandidateStartEvent childFragment = new CandidateStartEvent();
FragmentTransaction transaction =getFragmentManager().beginTransaction();
transaction.replace(R.id.childContainer, childFragment).addToBackStack(null).commit();
这篇关于我们可以在视图分页器的一个父片段中嵌套两个子片段吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!