Perform action on click of sliding drawer Handler

In my application I want to fill the sliding draw only when data is not null. So , when the user presses on the sliding drawer handler it should give a dialog "Data is empty" and sliding drawer should not open.

I have tried Handler.setOnTouchListener() but what happens is anywhere a touch event is called that dialog box appear.

Any suggestions?


You should take a look at the method setOnDrawerOpenListener.

Create your own OnDrawerOpenListener and use it to check if the data is null - if it is, close the drawer again:

private class OnDrawerOpened implements OnDrawerOpenListener {
  public void onDrawerOpened() {
    if( data == null )

You would need a reference to your SlidingDrawer and you would need OnDrawerOpened to be an inner class, so you can access the reference to your SlidingDrawer.


You could also create your own subclass by extending SlidingDrawer and then override the animateOpen() and open() methods (you might need to override animateToggle() and toggle() too):

public class MySlidingDrawer extends SlidingDrawer {

  public MySlidingDrawer( Context context, AttributeSet attrs ) {
    super( context, attrs );

  public void animateOpen() {
    if( data != null )    
      //Show dialog

  public void open() {
    if( data != null );
      //Show dialog

If you do this, you would need to reference your own implementation of the SlidingDrawer in your XML:


Depeding on how and when you get the data to check for null, you might want to either pass it to MySlidingDrawer in its constructor or add a method through which you can set the data.

Need Your Help

How to make UIButton move with UIScrollView

ios objective-c uiscrollview uibutton

I have a UIScrollView menu that moves above and below the viewport via the activation of a UIButton. The issue is that the button only stays in one place when I press it to make the UIScrollView menu

PowerShell Named Pipe: no connection?

powershell named-pipes

I need a named pipe to read and write.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.