Search code examples
androidonclickslidingmenubuttonclick

How can i move to any other activity with jfeinstein slider library


I have implemented jfeinstein10 slider menu library in my application. With this piece of code I am successfully able to implement slider in my app.

Now my question is how can I move to next activity using this slider? The following image shows how my slider looks like:

enter image description here

So basically I want to move to next activity or any other activity when I click on any of the options from slider. Like for example, when I click on Comment or Post or Chat or any other option I want to go to the relevant screen. Hope this is clear. Still if you need more explanation you can ask.

Following is my code snippet.

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final SlidingMenu menu = new SlidingMenu(this);
        menu.setMode(SlidingMenu.RIGHT);
        menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        menu.setFadeDegree(0.5f);
        menu.attachToActivity(MainActivity.this, SlidingMenu.SLIDING_CONTENT);
        menu.setMenu(R.layout.activity_menu);

        Button mButton = (Button) findViewById(R.id.slidingMenu);
        mButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                menu.showMenu();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
} 

Solution

  • You can define the onclick listenrs to the Menu layout that you have appended to the Main Activity like so:

      menu.getMenu().findViewById(R.id.yourSideMenuOption).setOnClickLister(this);
    

    Its advisable to use an abstract activity, so that you are not using the same code over and over in each of your activity.