Search code examples
javaandroidnavigation-drawer

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

  • try olia.setDrawerListener(this)