dequec64 February 2016

Wait until DrawerLayout animation is done

I have a drawerLayout (support.v4) with a navigationView and have many (like many up to n menu items) menu items. To have less items on the screen at the same time, some menu items lead to another menu with many items.

The thing is, my menu switch works fine, I'm able to pass from one menu to the other one but I have no animation... I want to close the drawer when an item linked to another menu is selected and once the menu is loaded, to open it again.

Here's my code:

navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem selectedItem) {
            mDrawerLayout.closeDrawer(GravityCompat.START);
            Log.d(MainActivity.class.getName(), selectedItem.toString());
            MobileXMLMenu menu = UserMenu.getInstance().getMenu();
            for(int i = 0; i < menu.sizeMenuItems(); i++){
                if(menu.getMenuItem(i).getLabel(Utility.retreiveLanguage()).equals(selectedItem.toString())){
                    Log.d(MainActivity.class.getName(), menu.getMenuItem(i).sizeMenuItems() + "");
                    if(menu.getMenuItem(i).sizeMenuItems() > 0){

                        Menu nMenu = navigationView.getMenu();
                        nMenu.clear();
                        for(int j = 0; j < menu.getMenuItem(i).sizeMenuItems(); j++){
                            MobileXMLMenuItem item = menu.getMenuItem(i).getMenuItem(j);
                            nMenu.add(item.getLabel(Utility.retreiveLanguage())).setIcon(MemberOptionsManager.getInstance().getMenuItemIcon(item.getDecorator()));
                        }
                        mDrawerLayout.openDrawer(GravityCompat.START);
                        isInSubmenu = true;
                    }
                }
            }
            return false;
        }
    });

I also have this for my ActionBarDrawerToggle (don't kn

Answers


rehman_mv February 2016

You can use callback methods of the drawer layout from official documentation of the android.

 onDrawerClosed(View drawerView)
 onDrawerOpened(View drawerView)
 onDrawerSlide(View drawerView, float slideOffset)
 onDrawerStateChanged(int newState)

You can find more at link:http://developer.android.com/reference/android/support/v4/widget/DrawerLayout.DrawerListener.html


topcbl February 2016

You can setDrawerListener on DrawLayout like this

        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, mDrawerLayout, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
            public void onDrawerClosed(View view) {
                handleClickNavigationItem(mClickedNavigationItem);
            }

            public void onDrawerOpened(View drawerView) {
            }
        };
        mDrawerLayout.setDrawerListener(toggle);

handleClickNavigationItem method contains the code which handle navigation event.

And just save clicked item in onNavigationItemSelected method

public boolean onNavigationItemSelected(MenuItem item) {
        mClickedNavigationItem = item.getItemId();
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
    return true;
}

Post Status

Asked in February 2016
Viewed 3,394 times
Voted 11
Answered 2 times

Search




Leave an answer