title: How to create a sliding menu on click of a button
body: <p>I want to create a sliding menu on click of a Button. I have used Sliding Menu library and Sherlock library. The sliding menu works well on swipe, but my requirement is i want the sliding menu to slide over when i click on the button. Please help.
  Thanks in advance</p>
  
  <p>MainPage code</p>
  
  <pre><code>package com.ketan.slidingexample;
  
  import android.os.Bundle;
  import android.widget.Button;
  import android.widget.TextView;
  
  import com.actionbarsherlock.app.ActionBar;
  import com.actionbarsherlock.app.SherlockFragmentActivity;
  import com.actionbarsherlock.view.Menu;
  import com.actionbarsherlock.view.MenuItem;
  import com.slidingmenu.lib.SlidingMenu;
  
  public class MainActivity extends SherlockFragmentActivity implements Menufragment.MenuClickInterFace{
      SlidingMenu menu;
      TextView text;
      Button btn;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          text=(TextView)findViewById(R.id.text);
          btn=(Button) findViewById(R.id.button1);
  
          ActionBar ab = getSupportActionBar();
          ab.setHomeButtonEnabled(true);
          ab.setDisplayHomeAsUpEnabled(true);
          menu = new SlidingMenu(this);
          menu.setMode(SlidingMenu.LEFT);
          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);
          menu.setSlidingEnabled(true);
  
      }
  
  
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // TODO Auto-generated method stub
          menu.toggle();
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      public void onListitemClick(String item) {
          // TODO Auto-generated method stub
          text.setText(item);
      }
  }
  </code></pre>
  
  <p>Menu Page code</p>
  
  <pre><code>package com.ketan.slidingexample;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.ListView;
  
  import com.actionbarsherlock.app.SherlockFragment;
  
  public class Menufragment extends SherlockFragment {
      ListView list;
      MenuClickInterFace mClick;
  
      interface MenuClickInterFace {
          void onListitemClick(String item);
      }
  
      @Override
      public void onAttach(Activity activity) {
          // TODO Auto-generated method stub
          super.onAttach(activity);
          mClick = (MenuClickInterFace) activity;
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onActivityCreated(savedInstanceState);
          list = (ListView) getView().findViewById(R.id.list);
          list.setOnItemClickListener(new OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2,
                      long arg3) {
                  String i=(String) arg0.getItemAtPosition(arg2);
                  mClick.onListitemClick(i);
              }
          });
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          View v = inflater.inflate(R.layout.menulist, container, false);
          return v;
      }
  
  }
  </code></pre>