-2

Here is my OnOptionItemSelected() and three other method for Toggle button

This the piece of code i have been written for Toggle button in MainActivity

         mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            R.drawable.humberg, //nav menu toggle icon
            R.string.app_name, // nav drawer open - description for accessibility
            R.string.app_name // nav drawer close - description for accessibility
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            // calling onPrepareOptionsMenu() to show action bar icons
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            // calling onPrepareOptionsMenu() to hide action bar icons
            invalidateOptionsMenu();
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    // Drawer Item click listeners
    mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItemFromDrawer(position);
        }

When i run my application im getting ERROR like UNFORTUNATELY YOUR APLLICATION HAS STOPPED.. }); This is my Logcat

prabhu
  • 89
  • 1
  • 8

2 Answers2

0

Your problem come from onPrepareOptionMenu() method, you actually not inflate any menu file to you activity, inflat your custom menu file in this method before set display or hide menu item. ps: sr for my english

0

Error says: RelativeLayout cannot be cast to DrawerLayout it's a ClassCastException.

Means:

Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance.

Explanation of "ClassCastException" in Java

or, means you are declaring a variable/object of some type and assigning it to another type you have defined

Community
  • 1
  • 1
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108