0

我创建了以下功能:

    private void openFilterStudentBottomSheetDialog(){
        View dialogView = getLayoutInflater().inflate(R.layout.bottomsheet_filter_students, null);
        BottomSheetDialog dialog = new BottomSheetDialog(this);
        dialog.setContentView(dialogView);

        tv_apply_student_filter=dialog.findViewById(R.id.tv_apply_student_filter);
        tabLayoutStudentList=dialog.findViewById(R.id.tabsStudentFilter);
        vpStudentList=dialog.findViewById(R.id.vpStudentFilter);

        StudentFilterPagerAdapter studentListPagerAdapter = new StudentFilterPagerAdapter(getSupportFragmentManager());
        vpStudentList.setAdapter(studentListPagerAdapter);
        vpStudentList.setOffscreenPageLimit(3);

        tabLayoutStudentList.setupWithViewPager(vpStudentList);

        tv_apply_student_filter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(StudentListActivity.this, "clicked", Toast.LENGTH_SHORT).show();
            }
        });

        dialog.show();
    }
}

我正在尝试打开 BottomSheet 对话框,其中包含一个按钮、选项卡和 viewpager。

正如您在上述方法中看到的那样,我可以成功单击按钮。

问题在于 ViewPager。我得到以下错误:

java.lang.IllegalArgumentException: No view found for id 0x7f090252 (packagename:id/vpStudentFilter) for fragment Filter_MonthListFragment{c832d8b #0 id=0x7f090252 android:switcher:2131296850:0}

可能是什么问题?

您可以检查如下布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:id="@+id/rl_container"
    android:layout_height="match_parent">
    <android.support.design.widget.TabLayout
        android:id="@+id/tabsStudentFilter"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabMode="fixed" />
    <android.support.v4.view.ViewPager
        android:id="@+id/vpStudentFilter"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/tv_apply_student_filter"
        android:layout_below="@+id/tabsStudentFilter"/>
    <TextView
        android:id="@+id/tv_apply_student_filter"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_margin="@dimen/size_10"
        android:background="@drawable/drawable_square_6dp_for_filter"
        android:gravity="center"
        android:padding="@dimen/size_12"
        android:text="Apply Filter"
        android:textColor="@color/colorWhite"
        android:textSize="@dimen/font_size_16" />
</RelativeLayout>

谢谢。

4

0 回答 0