我正在使用TabLayout播放片段。一旦我從TabLayout片段移動到下一個片段,然后按返回鍵。默認的TabLayout片段上的內容消失了。我在帖子中找到了可能的解決方案。以下是TabLayout的代碼。public class IndividualCollectionSheetFragment extends MifosBaseFragment {private TabLayout tabLayout;private ViewPager viewPager;private View rootView;public IndividualCollectionSheetFragment() {}public static IndividualCollectionSheetFragment newInstance() { Bundle args = new Bundle(); IndividualCollectionSheetFragment fragment = new IndividualCollectionSheetFragment(); fragment.setArguments(args); return fragment;}@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);}@Nullable@Overridepublic View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_individual_recycler, container, false); ButterKnife.bind(this, rootView); setToolbarTitle(getStringMessage(R.string.individual_collection_sheet)); viewPager = rootView.findViewById(R.id.viewpager); setupViewPager(viewPager); tabLayout = rootView.findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); return rootView;}帖子中的解決方案建議使用getChildFramentManager而不是getSupportFragmentManager。我一改成getChildFragmentManager。我得到了錯誤。 java.lang.IllegalStateException: Fragment CollectionSheetDialogFragment{572dd42 #0 Identifier Dialog Fragment} declared target fragment NewIndividualCollectionSheetFragment{45e8153 #0 id=0x7f090361 android:switcher:2131297121:0} that does not belong to this FragmentManager!這可能是由于擴展了DialogFragment的CollectionSheetDialogFragment類造成的,并且與所使用的不同片段管理器之間必須存在不一致之處。
添加回答
舉報
0/150
提交
取消