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?

Answers


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 {
  @Override
  public void onDrawerOpened() {
    if( data == null )
      mySlidingDrawer.close();
  }
}

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.

Alternative

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 );
  }

  @Override
  public void animateOpen() {
    if( data != null )    
      super.animateOpen();
    else
      //Show dialog
  }

  @Override
  public void open() {
    if( data != null )
      super.open();
    else
      //Show dialog
  }
}

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

<com.myPackage.MySlidingDrawer>
   ...
</com.myPackage.MySlidingDrawer>

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

autocomplete api php conversion error

php api autocomplete

I am trying to use api.autocomplete.com api

Why is my Tika Metadata object not being populated when using ForkParser?

java memory-management metadata content-type apache-tika

ForkParser is a new Tika parser that was introduced in Tika version 0.9, located in org.apache.tika.fork. The new parser forks off a new jvm process to analyze the passed file stream. I figured t...

Python call constructor in a member function

python oop constructor

Let's take for example this class, which is extending MySQLDB's connection object.