'onDrawerClosed and onDrawerOpened not being called

I am playing with the DrawerListener , and unfortunately the official documentation is not quite detailed, not to say there aren't any examples given.

All I want to test is showing a Toast message when the Drawer closes, but its just not happening, its not being called at all, any ideas ? Below the code

public class MainActivity extends ActionBarActivity implements DrawerLayout.DrawerListener {

  DrawerLayout.DrawerListener mele;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final DrawerLayout olia=(DrawerLayout)findViewById(R.id.container);

    ListView meka=(ListView)findViewById(R.id.left_drawer);

    String [] karo={"meka","deka","beka"};

    ArrayAdapter<String> mera=new ArrayAdapter<String>     ( this,android.R.layout.simple_list_item_1,karo);  

    meka.setAdapter(mera);

     olia.setDrawerListener(mele);      


    meka.setOnItemClickListener(new OnItemClickListener () {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub


              olia.closeDrawers();
        }



    });





}

@Override
public void onDrawerClosed(View arg0) {
    // TODO Auto-generated method stub


    Toast.makeText(MainActivity.this, "OK Opened", Toast.LENGTH_LONG).show();
    Log.d("meke", "CLOSED  DRAWER" );
}


Solution 1:[1]

try olia.setDrawerListener(this)

Solution 2:[2]

Since the method setDrawerListener(listener) is deprecated, you should use addDrawerListener(listener).

Solution 3:[3]

i have created a sample app for your issue Please check the solution , Now its working fine.

    public class YourActivity extends AppCompatActivity implements  DrawerLayout.DrawerListener {

    DrawerLayout drawer;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dash_board);
 final DrawerLayout olia=(DrawerLayout)findViewById(R.id.container);
        olia.setDrawerListener(this);
    }//onCreate()

    @Override
    public void onDrawerOpened(View arg0) {
      //write your code
    }

    @Override
    public void onDrawerClosed(View arg0) {

    }

    @Override
    public void onDrawerSlide(View arg0, float arg1) {
        //write your code
    }

    @Override
    public void onDrawerStateChanged(int arg0) {
        //write your code
    }
}//class

Solution 4:[4]

Note that setDrawerListener(DrawerLayout.DrawerListener) is deprecated.

Use addDrawerListener(DrawerLayout.DrawerListener) instead.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dumazy
Solution 2 Meyer
Solution 3 Gyan S Awasthi
Solution 4 Henry Ecker