Navigation drawer doesn't close

后端 未结 11 966
暖寄归人
暖寄归人 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:11

    use

    if(drawer.isDrawerOpen(navList))  
      {  
          drawer.closeDrawer(navList);      
      }
    

    In onResume() and start of onItemClick() method.

    or you can try another approach..run a Ui thread when you are selecting drawer item

    private void selectDrawerItemItem(final int position){
    
         //Toast.makeText(getApplicationContext(), "ItemClicked", Toast.LENGTH_SHORT).show();
    
         darwer.closeDrawer(navList);
    
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Fragment fragment = new Fragment(Activity.this);
                Bundle args = new Bundle();
                args.putInt(Fragment.ARG_PLANET_NUMBER, position);
                fragment.setArguments(args);
    
                FragmentManager fragmentManager = getSupportFragmentManager();
                 fragmentManager.beginTransaction().replace(R.id.content_frame,fragment).commit();
    
                // update selected item and title, then close the drawer
                navList.setItemChecked(position, true);
    
                setTitle(" " + navListTitles[position]);
            }
        }, 200);
    
    
        // update the main content by replacing fragments
    
    
    }
    

提交回复
热议问题