This SlidingMenu appears to already be attached Android

三世轮回 提交于 2019-12-10 11:52:22

问题


I getting following error

This SlidingMenu appears to already be attached

This my source code

SlidingMenu menu = new SlidingMenu(this, SlidingMenu.SLIDING_WINDOW);
menu.setMode(SlidingMenu.RIGHT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
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.menu);

I have used sliding menu library by jfeinstein

I want to slide menu with actionbar. Please help me.


回答1:


Problem

From the SlidingMenu.java in attachToActivity method

if (getParent() != null)
        throw new IllegalStateException("This SlidingMenu appears to already be attached");

here getParent is not null because you already assigned SlidingMenu.SLIDING_WINDOW when you create object of SlidingMenu.

e.g. SlidingMenu menu = new SlidingMenu(this, SlidingMenu.SLIDING_WINDOW);

above line of code calls attachToActivity. see in code

public SlidingMenu(Activity activity, int slideStyle) {
    this(activity, null);
    this.attachToActivity(activity, slideStyle);
}

So you are adding menu to layout twice. And that is the cause of problem.

Solution use one of the following.

  1. Use below constructor

    SlidingMenu menu = new SlidingMenu(this);

OR

  1. remove menu.attachToActivity(); line



回答2:


I met the same question. There is a R.java file in com.jeremyfeinstein.slidingmenu.lib,you might miss it. You can copy it from other SlidingMenu project into gen folder.



来源:https://stackoverflow.com/questions/25779814/this-slidingmenu-appears-to-already-be-attached-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!