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

autocomplete api php conversion error

php api autocomplete

I am trying to use 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.

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.