BottomSheetDialogFragment 内にビューページャーを設定しようとしていますが、常に同じ結果になります:
java.lang.IllegalStateException: フラグメントにビューがありません
セットアップダイアログ
コード:
@Override
public void setupDialog(Dialog dialog, int style) {
Log.d(TAG, "setupDialog");
super.setupDialog(dialog, style);
View root = View.inflate(getContext(), R.layout.fragment_daily_detail, null);
dialog.setContentView(root);
CoordinatorLayout.LayoutParams layoutParams =
(CoordinatorLayout.LayoutParams) ((View) root.getParent()).getLayoutParams();
CoordinatorLayout.Behavior behavior = layoutParams.getBehavior();
if (behavior != null && behavior instanceof BottomSheetBehavior) {
bottomSheetBehavior = (BottomSheetBehavior) behavior;
bottomSheetBehavior.setBottomSheetCallback(mBottomSheetBehaviorCallback);
bottomSheetBehavior.setPeekHeight((int) getResources().getDimension(R.dimen.fragment_forgot_password_min_height));
Log.d(TAG, "State: " + bottomSheetBehavior.getState());
imageClose = root.findViewById(R.id.imageViewClose);
textViewTitle = (TextView) root.findViewById(R.id.textViewTitle);
peekLayout = root.findViewById(R.id.peekLayout);
tabLayout = (TabLayout) root.findViewById(R.id.tabs);
viewPager = (ViewPager) root.findViewById(R.id.viewPager);
recyclerView = (RecyclerView) root.findViewById(R.id.recyclerView);
timesheetDay = timesheetDayList.get(pageNumber);
imageClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
}
});
textViewTitle.setText(timesheetDay.getDate());
sectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
viewPager.setAdapter(sectionsPagerAdapter);
tabLayout.setupWithViewPager(viewPager);
}
}
FragmentPagerAdapter
コード:
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return PageFragment.getInstance(timesheetDayList.get(position));
}
@Override
public int getCount() {
return timesheetDayList.size();
}
@Override
public CharSequence getPageTitle(int position) {
return timesheetDayList.get(position).getDate();
}
}
レイアウト コード:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_material_light"
android:clickable="true"
android:orientation="vertical"
tools:context=".ui.dialogs.bottomsheets.ForgotUsernameFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp">
<RelativeLayout
android:id="@+id/peekLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@color/colorPrimary"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageViewClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:padding="16dp"
app:srcCompat="@drawable/ic_close_white_24dp"
tools:ignore="MissingPrefix"
tools:src="@drawable/ic_close_white_24dp" />
<TextView
android:id="@+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Daily Detail"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/colorWhite" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout2"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:tabMode="scrollable" />
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
誰かがこの実装について何か知っていれば、私にとって非常に役に立ちます。
乾杯、よろしくお願いします!