0

/** Called when drawer is closed */

            public void onDrawerClosed(View view) 
           {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu();
           }

/** Called when a drawer is opened */

          public void onDrawerOpened(View drawerView) 
         {
            getActionBar().setTitle("Select a river");
            invalidateOptionsMenu();
        }

    };

// Setting DrawerToggle on DrawerLayout

           mDrawerLayout.setDrawerListener(mDrawerToggle);

// Creating an ArrayAdapter to add items to the listview mDrawerList

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                getBaseContext(), 
                R.layout.drawer_list_item  , 
                getResources().getStringArray(R.array.rivers) 
            );

// Setting the adapter on mDrawerList

    mDrawerList.setAdapter(adapter);

// Enabling Home button

    getActionBar().setHomeButtonEnabled(true);

// Enabling Up navigation

    getActionBar().setDisplayHomeAsUpEnabled(true);
prabhu
  • 1
  • 1
  • can you post the logcat output. what's the exact error ? – Shivam Verma Jun 18 '14 at 05:54
  • Are you sure you are calling this from Fragment? Fragment does not have method `getActionBar();` [Read this.](http://stackoverflow.com/questions/12013849/cant-get-action-bar-in-fragment-class) – Marius Jun 18 '14 at 06:02
  • IN Android Maninfest file if i change min sdk version 14 means I am getting output.But i use min sdk version 8 means i doesnot getting error. – prabhu Jun 18 '14 at 06:11

2 Answers2

0

Try to use getSupportActionBar() instead of getActionBar().

Gunaseelan
  • 14,415
  • 11
  • 80
  • 128
0

Fragment does not have method getActionBar(). A fragment is usually used as part of an activity's user interface and contributes its own layout to the activity. To provide a layout for a fragment, you must implement the onCreateView() callback method, which the Android system calls when it's time for the fragment to draw its layout. So, fragment requires its activity in which it is present.

So, try getActivity().getActionBar();

Deepak G
  • 677
  • 9
  • 10