Question

I have an activity, where using the Sliding Menu library, i try to create 2 sliding menus. This is the code i tried:

 FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
    menu = new SlidingMenu(this);
    menu.setMode(SlidingMenu.RIGHT);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
    menu.setShadowWidthRes(R.dimen.shadow_width);
    menu.setShadowDrawable(R.drawable.shadow);
    menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    menu.setFadeDegree(0.35f);
    menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
    menu.setMenu(R.layout.tutorial_layout);
    rightSlide = new HelpFragment();
    t.replace(R.id.slidingList2, rightSlide);
    t.commit();
    menu.setSecondaryMenu(R.layout.log_history);
    leftSlide = new LogHistory();
    t.replace(R.id.loghistorycon, leftSlide);
    t.commit();

Now i get a ANR error, and Logcat says, that the FragmentTransaction t, has already been commited. I looked at the example from: github.com/jfeinstein10/SlidingMenu and it allows him to do 2 commit's:

 setContentView(R.layout.content_frame);
    getSupportFragmentManager()
    .beginTransaction()
    .replace(R.id.content_frame, new SampleListFragment())
    .commit();

    getSlidingMenu().setSecondaryMenu(R.layout.menu_frame_two);
    getSlidingMenu().setSecondaryShadowDrawable(R.drawable.shadowright);
    getSupportFragmentManager()
    .beginTransaction()
    .replace(R.id.menu_frame_two, new SampleListFragment())
    .commit();

What am I doing wrong? i just can't see the difference

Was it helpful?

Solution

Change your above code as below

 FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
    menu = new SlidingMenu(this);
    menu.setMode(SlidingMenu.RIGHT);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
    menu.setShadowWidthRes(R.dimen.shadow_width);
    menu.setShadowDrawable(R.drawable.shadow);
    menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    menu.setFadeDegree(0.35f);
    menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
    menu.setMenu(R.layout.tutorial_layout);
    rightSlide = new HelpFragment();
    t.replace(R.id.slidingList2, rightSlide);
    t.commit();
    t = this.getSupportFragmentManager().beginTransaction();
    menu.setSecondaryMenu(R.layout.log_history);
    leftSlide = new LogHistory();
    t.replace(R.id.loghistorycon, leftSlide);
    t.commit();

For a FragmentTransaction, you can have only one commit. In your code you created a FragmentTransaction object and called commit once for rightSlide. So t is not usable for transactions anymore. So you have create another FragmentTransaction as I have done in the above code. I hope this will work for you.

OTHER TIPS

@LLL Following code is working Properly to me.i hope,it help u more...

    SlidingMenu slidingMenu  = getSlidingMenu();slidingMenu.setMode(SlidingMenu.LEFT_RIGHT);
    slidingMenu.setShadowWidthRes(R.dimen.shadow_width);
    slidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    slidingMenu.setFadeDegree(0.35f);
    slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
    slidingMenu.setMenu(R.layout.profile);
    slidingMenu.setSecondaryMenu(R.layout.nextactivity);
    Button csButton=(Button)findViewById(R.id.txtx);
    inside csButton onclick listener just need to call slidingMenu.showSecondaryMenu();
    and, Button csButton1=(Button)findViewById(R.id.button1);
    inside csButton1 onclick listener just need to call slidingMenu.showMenu();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top