ViewPager inside BottomSheetDialogFragment
Try to change your code like below:
...
LayoutInflater inflater = getActivity().getLayoutInflater();
root = inflater.inflate(R.layout.fragment_daily_detail, null);
...
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
//Use getSupportFragmentManager() instead of getChildFragmentManager(),
...
UPDATED
I solved the problem inflating the view in "onCreateView()". Anyway, I have setted a RecyclerView inside the ViewPager and the RecyclerView vertical scroll is very unstable, sometimes works and sometimes doesn't, so I'll try do this screen in another way.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.d(TAG, "onCreateview");
View root = inflater.inflate(R.layout.fragment_daily_detail, container);
mImageClose = root.findViewById(R.id.imageViewClose);
mTextViewTitle = (TextView) root.findViewById(R.id.textViewTitle);
mPeekLayout = root.findViewById(R.id.peekLayout);
mTabLayout = (TabLayout) root.findViewById(R.id.tabs);
mViewPager = (ViewPager) root.findViewById(R.id.viewPager);
mImageClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getDialog().dismiss();
}
});
mTextViewTitle.setText("Daily detail");
mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
mViewPager.setAdapter(mSectionsPagerAdapter);
mTabLayout.setupWithViewPager(mViewPager);
mViewPager.setCurrentItem(mPageNumber);
mPeekLayout.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
BottomSheetDialog dialog = (BottomSheetDialog) getDialog();
FrameLayout bottomSheet = (FrameLayout) dialog.findViewById(android.support.design.R.id.design_bottom_sheet);
mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
// gets called after layout has been done but before display
// so we can get the height then hide the view
int height = mPeekLayout.getHeight();
Log.d(TAG, "Height: " + height);
mBottomSheetBehavior.setPeekHeight(height);
mBottomSheetBehavior.setBottomSheetCallback(mBottomSheetBehaviorCallback);
}
});
return root;
}