Anas Azeem
Anas Azeem

Reputation: 2830

SlidingMenu : Showing seconday menu on an event

I am using the awesome library SlidingMenu by jfeinstein10. So, everything is is going just right but one thing.

I am able to open the primary menu using the method toggle() in an event handler. But I also want the secondary menu to open on some event like button click.

I did something like

SlidingMenu right = getSlidingmenu();
right.setSecondaryMenu(rightMenuView)

and was thinking of doing right.toggle(); but the second statement above throws a NullPointerException.

Edit : Posting onCreate

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    leftMenuView = inflater.inflate(R.layout.left_menu, null, false);
    rightMenuView = inflater.inflate(R.layout.right_menu, null, false);
    customActionBarView = inflater.inflate(R.layout.custom_actionbar,null);

    findAllViews();
    setFontAwesome();

    ab = getSupportActionBar();
    ab.setDisplayShowCustomEnabled(true);
    ab.setDisplayHomeAsUpEnabled(false);
    ab.setDisplayShowHomeEnabled(false);
    ab.setDisplayUseLogoEnabled(false);
    ab.setCustomView(R.layout.custom_actionbar);
    ivHome = (ImageView) findViewById(R.id.ab_home); 
    ivHome.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Log.d("TAG", "Tag");
            toggle();
        }
    });


    leftSlidingMenu = getSlidingMenu();
    leftSlidingMenu.setMode(SlidingMenu.LEFT_RIGHT);
    setBehindContentView(leftMenuView);
    leftSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    leftSlidingMenu.setBehindOffset(100);
    leftSlidingMenu.setFadeDegree(0.35f);

    rightSlidingMenu = getSlidingMenu();
            rightSlidingMenu.setSecondaryMenu(rightMenuView); //NPE Here
            rightSlidingMenu.toggle();  
}

Any idea how to open secondary menu on an event. Thank You

Upvotes: 3

Views: 2306

Answers (2)

MD SHAHIDUL ISLAM
MD SHAHIDUL ISLAM

Reputation: 14523

In BaseActivity modify as following

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        toggle();
        return true;
    case R.id.github:
        //Util.goToGitHub(this); //remove this line
        showSecondaryMenu(); //add this line
        return true;
    }
    return super.onOptionsItemSelected(item);
}

Upvotes: 1

Macarse
Macarse

Reputation: 93133

To show the second menu you can use:

getSlidingMenu().showSecondaryMenu(true);

The boolean parameter is the animation flag.

Upvotes: 8

Related Questions