2

How can I open a SlidingDrawer using a button not attached to it? In other words, I like to open it w/o the handle.

4 Answers4

7

Call open() on the SlidingDrawer.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • what do you mean by open() means where to apply on sliding drawer. Can you please explain – Nikki Feb 11 '11 at 05:04
  • 1
    @Nikki: `SlidingDrawer` is what we refer to in Java as a "class". You have an "instance" of this "class" that is your actual drawer. The "class" has a "method" that is named `open()`. You can call `open()` on the "instance" to open the drawer. – CommonsWare Feb 11 '11 at 12:12
  • Thanks for reply. But how to know by sliding drawer, on which button it has to open – Nikki Feb 11 '11 at 12:33
5

Calling .open() and .close() makes the drawer appear and disappear without animation. I don't know if this is generally the case - I tested this on 4.03 with the drawer in a RelativeLayout and it just popped into view without animation.

To make the SlidingDrawer open and close by sliding into the View when clicking a button, use:

slidingDrawer.animateOpen();

and

slidingDrawer.animateClose();
Gunnar Karlsson
  • 28,350
  • 10
  • 68
  • 71
2

Im not sure if you still need help or not but I was just wondering the same thing.

"SlidingDrawer" is our object called "slider":

SlidingDrawer slider = (SlidingDrawer) findViewById(R.id.SlidingDrawer);

Call the method "open()", using our object name:

slider.open();

Example button that just opens the sliding drawer:

Button next = (Button) findViewById(R.id.Button01);
next.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        slider.open();
    }
});

enter image description here

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
0

You need to override the handle's touch method(s) and pass down the touch event to the button.

KITT
  • 230
  • 2
  • 3
  • 15