1

I am using SlidingMenu with ActionBarSherlock in my app and the way I have implemented it is by making a BaseActivity which extends SlidingFragmentActivity ( similar to the way they showed in the example ). Every other activity in my app extends this BaseActivity.

But currently, when I slide from the left in the App, the entire activity including the ActionBar slides. I only want the content to slide. So looking at the docs, I figured that adding this should do it: menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);

But I get an error for that line -

java.lang.IllegalStateException: This SlidingMenu appears to already be attached

Here's the onCreate function of the BaseActivity -

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setTitle(mTitleRes);

        // set the Behind View
        setBehindContentView(R.layout.menu_frame);
        if (savedInstanceState == null) {
            FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
            mFrag = new MenuListFragment();
            t.replace(R.id.menu_frame, mFrag);
            t.commit();
        } else {
            mFrag = (ListFragment)this.getSupportFragmentManager().findFragmentById(R.id.menu_frame);
        }

        // customize the SlidingMenu
        SlidingMenu sm = getSlidingMenu();
        sm.setShadowWidthRes(R.dimen.shadow_width);
        sm.setShadowDrawable(R.drawable.shadow);
        sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        sm.setFadeDegree(0.35f);
        sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

   // **** This following line causes the error  *****
        sm.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

Should I be doing the attachToActivity somewhere else?

Ayrton Senna
  • 3,735
  • 5
  • 34
  • 52

2 Answers2

5

I eventually solved it by removing this from the Base activity - sm.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);

and just adding this to the onCreate of all the inherited Activities:

setSlidingActionBarEnabled(false);

I guess this is coming from a long line of inheritance (myActivity --> BaseActivity ---> SlidingFragmentActivity --> SherlockFragmentActivity)

Ayrton Senna
  • 3,735
  • 5
  • 34
  • 52
  • I can't get this i tried the above but still i can't scroll horizontally in view pager or gallery in my fragment. Any clues ? – abhishek Aug 14 '14 at 20:52
1

You used the command line:

SlidingMenu sm = getSlidingMenu();

and you didn't attach the your menu because your menu is already attached.

use the command:

sm.attachToActivity(this, SlidingMenu.SLIDING_WINDOW); 

if you create a new instance of SlidingMenu. Like a SlidingMenu menu = new SlidingMenu(this);

Stewie Griffin
  • 14,889
  • 11
  • 39
  • 70