Skip to content Skip to sidebar Skip to footer

Navigation Drawer Doesn't Close

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 it should but whe

Solution 1:

have you tried :

mDrawerLayout.closeDrawer(drawerListView);

You can add this before calling startActivity()

Solution 2:

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 = = newRunnable() {
    @Overridepublicvoidrun() {
         //sayselectItem(pos); //Implement your switch case logic in this func
    }
}

and then in the onDrawerClosed overrided method

@OverridepublicvoidonDrawerClosed(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

Solution 3:

Call

drawer.closeDrawer(navList);

in onItemClick() method

Solution 4:

Try

drawer.closeDrawer(Gravity.START);

Your drawer gravity is start so Use that to close the corresponding drawer

Solution 5:

I didn't see any code where you are closing the ListView from drawer... close the ListView Drawer on ListItem click...

    navList.setOnItemClickListener(newAdapterView.OnItemClickListener(){
        @OverridepublicvoidonItemClick(AdapterView<?> parent, View view, finalint pos,long id){
            drawer.closeDrawer(navList);
            switch (pos){
                case0:
                    Intenti=newIntent(MainActivity.this,Aluminium.class);
                    startActivity(i);
                    break;
                case1:
                    Intenti2=newIntent(MainActivity.this,Gold.class);
                    startActivity(i2);
                    break;
                case2:
                    Intenti3=newIntent(MainActivity.this,Zinc.class);
                    startActivity(i3);
                    break;
            }
        }
    });

Post a Comment for "Navigation Drawer Doesn't Close"