Navigation drawer doesn't close

后端 未结 11 1162
暖寄归人
暖寄归人 2021-02-08 03:44

The navigation drawer in my app is not closing. I am using activities instead of fragments. When i click on any item in the listview, it opens other activities as i

11条回答
  •  我寻月下人不归
    2021-02-08 04:20

    In continuation to others answers and @ Chinmay Dabke question of 'but the drawer closes half then pauses and then closes fully' in one of the comments, here is what you could do:

    first as others suggested, this line is missing. drawer.closeDrawer(navList);

    And as far as the pausing of drawer is concerned while closing, you could do something like this. use a Runnable and a Handler like this:

    mRunnable = = new Runnable() {
        @Override
        public void run() {
             //say
             selectItem(pos); //Implement your switch case logic in this func
        }
    }
    

    and then in the onDrawerClosed overrided method

    @Override
    public void onDrawerClosed(View view) {
    
    if (mRunnable != null) {
        mHandler.post(mRunnable);
        mRunnable = null;
    }
    }
    

    Hope this helps!

    I would suggest you to use fragments for navigation drawer and to solve this issue of drawer not closing properly, I found this article very useful (using fragments). http://www.michenux.net/android-asynctask-in-fragment-best-pratices-725.html

提交回复
热议问题