-1

i have a class which extends fragment. i have a slidingdrawer which i want to do is, if the slidingdrawer is opened then when user touch outside the slidingdrawer, it should automatically closed. my code for manually open and close is like:

        final Button slideButton;
        final SlidingDrawer slidingDrawer;
        slideButton = (Button) view.findViewById(R.id.slideButton);
        slidingDrawer = (SlidingDrawer) view.findViewById(R.id.SlidingDrawer);

        slideButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if(slidingDrawer.isOpened())
                    slidingDrawer.animateClose();
                else
                    slidingDrawer.animateOpen();
            }
        });

        slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {

            @Override
            public void onDrawerOpened() {
                slideButton.setBackgroundResource(R.drawable.openarrow);

            }
        });

        slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
            @Override
            public void onDrawerClosed() {
                slideButton.setBackgroundResource(R.drawable.closearrow);
            }
        });

how can i achieve that ??

Shoshi
  • 2,254
  • 1
  • 29
  • 43

1 Answers1

3

I'm not sure how you're implementing the sliding drawer, but you can do this similar to closing the keyboard with a touch outside, like this:

https://stackoverflow.com/a/11656129/901309

But instead of closing the keyboard, close your sliding drawer. You'll need to pass the setupUI() method the View (LinearLayout, RelativeLayout, etc.) that contains everything except the sliding drawer.

Also, remove the "if(!(view instanceof EditText))" check.

Community
  • 1
  • 1