2

我的应用程序中有两个导航抽屉和一个底页。我想通过单击导航抽屉中的项目来展开底部工作表。导航抽屉工作得很好。

更新了 xml....

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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/drawer_layout_widget"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:focusableInTouchMode="true">

    <android.support.design.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/bg_register"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            tools:context="com.ceatkelanisrilanka.dushanmadushanka.ceat.CeatMainActivity"
            tools:showIn="@layout/activity_ceat_main">

            <include
                android:id="@+id/app_bar"
                layout="@layout/app_toolbar_welcome_menu"></include>

            <com.rey.material.widget.ProgressView
                android:id="@+id/pViewew"
                cpd_strokeColor="@android:color/holo_red_dark"
                cpd_strokeSecondaryColor="@android:color/holo_blue_bright"
                cpd_strokeSize="25dp"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_alignTop="@+id/txtMonthSn"
                android:layout_centerHorizontal="true"
                app:pv_autostart="true"
                app:pv_circular="true"
                app:pv_progressMode="indeterminate"
                app:pv_progressStyle="@style/Material.Drawable.CircularProgress" />

            <TextView
                android:id="@+id/txtMonth"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/app_bar"
                android:layout_alignStart="@+id/app_bar"
                android:layout_below="@+id/app_bar"
                android:layout_marginTop="2dp"
                android:paddingLeft="10dp"
                android:text="Month"
                android:textColor="#ffffff"
                android:textSize="24sp" />

            <TextView
                android:id="@+id/txtMonthSn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_alignTop="@+id/txtMonth"
                android:paddingRight="10dp"
                android:text="MonthSn"
                android:textColor="#ffffff"
                android:textSize="24sp" />


            <TextView
                android:id="@+id/yearTextV"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignEnd="@+id/txtMonth"
                android:layout_alignRight="@+id/txtMonth"
                android:layout_below="@+id/txtMonth"
                android:text="year"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="#ffffff" />

            <RelativeLayout
                android:id="@+id/relativeLayout2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/relativeLayout"
                android:layout_marginBottom="18dp">

                <com.github.lzyzsd.circleprogress.ArcProgress
                    android:id="@+id/arc_progress"
                    android:layout_width="220dp"
                    android:layout_height="220dp"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="20dp"
                    android:layout_marginStart="20dp"
                    android:padding="5dp" />

            </RelativeLayout>

            <!-- <com.github.lzyzsd.circleprogress.ArcProgress
                 android:id="@+id/arc_progress_two"
                 android:layout_width="100dp"
                 android:layout_height="100dp"
                 android:layout_alignParentEnd="true"
                 android:layout_alignParentRight="true"
                 android:layout_centerVertical="true"
                 android:layout_marginEnd="20dp"
                 android:layout_marginRight="20dp"
                 android:padding="5dp"
                 app:arc_bottom_text="Precentage" />-->
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/relativeLayout2"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_marginBottom="22dp"
                android:layout_marginEnd="20dp"
                android:layout_marginRight="20dp"
                android:gravity="center"
                android:orientation="vertical">

                <com.hookedonplay.decoviewlib.DecoView
                    android:id="@+id/dynamicArcView"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:padding="5dp" />

                <TextView
                    android:id="@+id/pView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="0 %"
                    android:textColor="#4B73C4"
                    android:textSize="20sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Precentage"
                    android:textColor="#4B73C4"
                    android:textSize="15sp" />

            </LinearLayout>


            <RelativeLayout
                android:id="@+id/relativeLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_marginBottom="23dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp">

                <TextView
                    android:id="@+id/txtMtar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignTop="@+id/txtTarget"
                    android:padding="5dp"
                    android:text="Monthly Target"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#ffffff" />

                <TextView
                    android:id="@+id/txtPre"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_below="@+id/txtMAch"
                    android:layout_marginTop="40dp"
                    android:padding="5dp"
                    android:text="Percentage"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#ffffff" />

                <TextView
                    android:id="@+id/txtMAch"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_marginTop="80dp"
                    android:padding="5dp"
                    android:text="Achievment"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#ffffff" />

                <TextView
                    android:id="@+id/txtTarget"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_above="@+id/txtAchievement"
                    android:layout_alignLeft="@+id/txtAchievement"
                    android:layout_alignStart="@+id/txtAchievement"
                    android:layout_marginBottom="35dp"
                    android:padding="5dp"
                    android:text="M"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#ffffff" />

                <TextView
                    android:id="@+id/txtAchievement"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_above="@+id/txtPre"
                    android:layout_centerHorizontal="true"
                    android:padding="5dp"
                    android:text="M"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#ffffff" />

                <TextView
                    android:id="@+id/txtCollection"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBottom="@+id/txtPre"
                    android:layout_alignLeft="@+id/txtAchievement"
                    android:layout_alignStart="@+id/txtAchievement"
                    android:padding="5dp"
                    android:text="M"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#ffffff" />

                <Button
                    android:id="@+id/bValue"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="120dp"
                    android:layout_height="wrap_content"
                    android:layout_alignBaseline="@+id/txtAchievement"
                    android:layout_alignBottom="@+id/txtAchievement"
                    android:layout_alignLeft="@+id/bTon"
                    android:layout_alignStart="@+id/bTon"
                    android:text="Value"
                    android:textColor="@color/border_gray" />

                <Button
                    android:id="@+id/bTon"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="120dp"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentRight="true"
                    android:layout_alignTop="@+id/txtTarget"
                    android:text="Ton"
                    android:textColor="@color/border_gray" />

                <Button
                    android:id="@+id/bCollection"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="120dp"
                    android:layout_height="wrap_content"
                    android:layout_alignBottom="@+id/txtCollection"
                    android:layout_alignLeft="@+id/bValue"
                    android:layout_alignStart="@+id/bValue"
                    android:text="Collection"
                    android:textColor="@color/border_gray" />

            </RelativeLayout>

        </RelativeLayout>


        <include
            android:id="@+id/bottom_sheet"
            layout="@layout/bottom_sheet" />

    </android.support.design.widget.CoordinatorLayout>

    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="com.ceatkelanisrilanka.dushanmadushanka.ceat.fragments.NavigationDrawerFragment"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer"></fragment>

    <fragment
        android:id="@+id/month_navigation_drawer"
        android:name="com.ceatkelanisrilanka.dushanmadushanka.ceat.fragments.MonthNavigationDrawerFragment"
        android:layout_width="@dimen/month_nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        app:layout="@layout/month_navigation_drawer"
        tools:layout="@layout/month_navigation_drawer"></fragment>

</android.support.v4.widget.DrawerLayout>

My MonthNavigationDrawerFragment recyclerview click

recyclerView.addOnItemTouchListener(new RecycleTouchListner(getActivity(), recyclerView, new ClickListener() {
            @Override
            public void onClick(View view, int position) {
                switch (position) {
                    case 0:
                        welcomeMenu.openBottomSheet();
                        mDrawerlayout.closeDrawers();
                        break;

                    case 1:
                     ......
                }
            }

        }));
        return vieww;
    }

我的 WelcomeMenu 类

    public class WelcomeMenu extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.welcome_menu);

            vollySingleton = VollySingleton.getsInstance();
            requestQueue = vollySingleton.getmRequestQueue();

            typeface = Typeface.createFromAsset(getAssets(), "helvr.ttf");
            snTypeFace = Typeface.createFromAsset(getAssets(), "DL_PARAS.TTF");
            welcomScreenTypeface = Typeface.createFromAsset(getAssets(), "productsans.ttf");

            progressView = (ProgressView) findViewById(R.id.pViewew);

            bottomSheet = findViewById(R.id.bottom_sheet);
            bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
            initState = BottomSheetBehavior.STATE_COLLAPSED;

            bottomSheet.post(new Runnable() {
                @Override
                public void run() {
                    bottomSheetBehavior.setState(initState);
                }
            });

            toolbar = (Toolbar) findViewById(R.id.app_bar);
            setSupportActionBar(toolbar);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setTitle("Achivements");

            NavigationDrawerFragment navigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
            navigationDrawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout_widget), toolbar);

            MonthNavigationDrawerFragment monthNavigationDrawerFragment = (MonthNavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.month_navigation_drawer);
            monthNavigationDrawerFragment.setUp(R.id.month_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout_widget), toolbar);

            final Calendar calendar = Calendar.getInstance();
            SimpleDateFormat month_date = new SimpleDateFormat("MMMM");
            String month_name = month_date.format(calendar.getTime());
            int year_name = calendar.get(calendar.YEAR);
            int monthNo = calendar.get(Calendar.MONTH);

            txtTarget = (TextView) findViewById(R.id.txtTarget);
            txtAchievement = (TextView) findViewById(R.id.txtAchievement);
            txtCollection = (TextView) findViewById(R.id.txtCollection);
            txtMonth = (TextView) findViewById(R.id.txtMonth);
            txtMonthSn = (TextView) findViewById(R.id.txtMonthSn);
            txtYear = (TextView) findViewById(R.id.yearTextV);
            txtM_tar = (TextView) findViewById(R.id.txtMtar);
            txtM_ach = (TextView) findViewById(R.id.txtMAch);
            txtM_prec = (TextView) findViewById(R.id.txtPre);
            arcProgress = (ArcProgress) findViewById(R.id.arc_progress);
            pView = (TextView) findViewById(R.id.pView);
            //arcProgressPrecentage = (ArcProgress) findViewById(R.id.arc_progress_two);

            df = new SimpleDateFormat("yyyy-MM");
            systemDate = df.format(new Date());

            arcView = (DecoView) findViewById(R.id.dynamicArcView);

            bTon = (Button) findViewById(R.id.bTon);
            bValue = (Button) findViewById(R.id.bValue);
            bCollection = (Button) findViewById(R.id.bCollection);

            txtMonth.setText(month_name);
            txtMonth.setTypeface(typeface);
            txtM_prec.setTypeface(welcomScreenTypeface);
            txtM_ach.setTypeface(welcomScreenTypeface);
            txtM_tar.setTypeface(welcomScreenTypeface);
            txtYear.setText(String.valueOf(year_name));

            db = new SQLiteHandler(getApplicationContext());

            // session manager
            session = new SessionManager(getApplicationContext());

            if (!session.isLoggedIn()) {
                logoutUser();
            } else {
                //pass button click operation
                getJsonRequest(bTon, bCollection, bValue, systemDate);
            }

        }
public void openBottomSheet() {
        bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
        bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);

    }
}

日志猫

10:11:48.907 18943-18943/com.ceatkelanisrilanka.dushanmadushanka.ceat E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                              Process: com.ceatkelanisrilanka.dushanmadushanka.ceat, PID: 18943
                                                                                              java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.design.widget.BottomSheetBehavior.setState(int)' on a null object reference
                                                                                                  at com.ceatkelanisrilanka.dushanmadushanka.ceat.WelcomeMenu.openBottomSheet(WelcomeMenu.java:816)
                                                                                                  at com.ceatkelanisrilanka.dushanmadushanka.ceat.fragments.MonthNavigationDrawerFragment$1.onClick(MonthNavigationDrawerFragment.java:87)
                                                                                                  at com.ceatkelanisrilanka.dushanmadushanka.ceat.fragments.MonthNavigationDrawerFragment$RecycleTouchListner.onInterceptTouchEvent(MonthNavigationDrawerFragment.java:239)
                                                                                                  at android.support.v7.widget.RecyclerView.dispatchOnItemTouchIntercept(RecyclerView.java:2206)
                                                                                                  at android.support.v7.widget.RecyclerView.onInterceptTouchEvent(RecyclerView.java:2252)
                                                                                                  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1960)
                                                                                                  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
                                                                                                  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
                                                                                                  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
                                                                                                  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
                                                                                                  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
                                                                                                  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
                                                                                                  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
                                                                                                  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
                                                                                                  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
                                                                                                  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
                                                                                                  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
                                                                                                  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
                                                                                                  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
                                                                                                  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
                                                                                                  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2369)
                                                                                                  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1719)
                                                                                                  at android.app.Activity.dispatchTouchEvent(Activity.java:2742)
                                                                                                  at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
                                                                                                  at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
                                                                                                  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2330)
                                                                                                  at android.view.View.dispatchPointerEvent(View.java:8666)
                                                                                                  at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4123)
                                                                                                  at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3989)
                                                                                                  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
                                                                                                  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3597)
                                                                                                  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3563)
                                                                                                  at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3680)
                                                                                                  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3571)
                                                                                                  at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3737)
                                                                                                  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
                                                                                                  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3597)
                                                                                                  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3563)
                                                                                                  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3571)
                                                                                                  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
                                                                                                  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5807)
                                                                                                  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5781)
                                                                                                  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5752)
                                                                                                  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5897)
                                                                                                  at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
                                                                                                  at android.os.MessageQueue.nativePollOnce(Native Method)
                                                                                                at android.os.MessageQueue.next(MessageQueue.jav
04-20 10:16:48.999 18943-18943/com.ceatkelanisrilanka.dushanmadushanka.ceat I/Process: Sending signal. PID: 18943 SIG: 9
4

1 回答 1

1

您可以尝试先关闭导航抽屉然后打开底部工作表只是尝试交换代码行

于 2016-04-20T04:28:20.003 回答