Search code examples
androidactionbarsherlock

getSupportMenuInflater() and getSherlockActivity() not recognised in actionbarsherlock android


I have been trying to inflate a menu using actionbarsherlock, but no luck. please suggest what is wrong. here is my code:

 @Override
        public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {

            MenuInflater inflater=getSherlockActivity().getSupportMenuInflater(); //getSherlockActivity() not recognised
inflater.inflate(R.menu.widgets_menu, menu);

  // I have also tried this:
//MenuInflater inflater=getSupportMenuInflater();// getSupportMenuInflater() not recognized
//inflater.inflate(R.menu.widgets_menu, menu);

 return true;

        }

Note: I have imported all the necessary classes

import com.actionbarsherlock.ActionBarSherlock;
import com.actionbarsherlock.ActionBarSherlock.OnCreateOptionsMenuListener;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;

Thanks in advance.


Solution

  • Finally got the answer. Thanks to @petrch.

    I just extended my activity class to SherlockActivity.

    @Override
            public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
    
                MenuInflater inflater=getSherlockActivity().getSupportMenuInflater(); 
    inflater.inflate(R.menu.widgets_menu, menu);
    
     return true;
    
            }