0

I tried to implements two navigation drawer on same activity, I am following this post to do it Two Navigation Drawer on same Activity, but when I tried to capture onItemClick in ListView Nothing it happens. Thanks in advance for help.

Below is my code..

MainActivity.java

public class MainActivity extends ActionBarActivity
     {
         DrawerLayout mDrawerlayout;
         ListView mDrawerList_Left,mDrawerList_Right;
         ActionBarDrawerToggle mDrawerToggle;
         ImageButton imgLeftMenu,imgRightMenu;


         NavDrawerAdapter Left_Adapter;
         NavDrawerAdapter Right_Adapter;

         @Override
         protected void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.activity_main);

             //===============Initialization of Variables=========================//

             mDrawerlayout=(DrawerLayout)findViewById(R.id.drawer_layout);
             mDrawerList_Left=(ListView)findViewById(R.id.drawer_list_left);
             mDrawerList_Left.setOnItemClickListener(new DrawerItemClickListener());
             mDrawerList_Right=(ListView)findViewById(R.id.drawer_list_right);
             imgLeftMenu=(ImageButton)findViewById(R.id.imgLeftMenu);
             imgRightMenu=(ImageButton)findViewById(R.id.imgRightMenu);
             mDrawerlayout.setDrawerListener(mDrawerToggle);

             //============== Define a Custom Header for Navigation drawer=================//

             LayoutInflater inflator=(LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             View v=inflator.inflate(R.layout.header, null);

             imgLeftMenu=(ImageButton)v.findViewById(R.id.imgLeftMenu);
             imgRightMenu=(ImageButton)v.findViewById(R.id.imgRightMenu);

             getSupportActionBar().setHomeButtonEnabled(true);

             // getSupportActionBar().setDisplayHomeAsUpEnabled(true);

             getSupportActionBar().setDisplayShowTitleEnabled(false);

             getSupportActionBar().setDisplayUseLogoEnabled(false);

             getSupportActionBar().setDisplayShowCustomEnabled(true);

             getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#1281A9")));

             getSupportActionBar().setIcon(
                     new ColorDrawable(getResources().getColor(android.R.color.transparent)));

             getSupportActionBar().setCustomView(v);
             imgLeftMenu.setOnClickListener(new View.OnClickListener() {

                 @Override
                 public void onClick(View arg0) {
                     // TODO Auto-generated method stub
                     if (mDrawerlayout.isDrawerOpen(mDrawerList_Right)){
                         mDrawerlayout.closeDrawer(mDrawerList_Right);

                     }
                     mDrawerlayout.openDrawer(mDrawerList_Left);
                     mDrawerList_Left.bringToFront();
                     mDrawerlayout.requestLayout();
                 }
             });


             imgRightMenu.setOnClickListener(new View.OnClickListener() {

                 @Override
                 public void onClick(View v) {
                     // TODO Auto-generated method stub
                     if (mDrawerlayout.isDrawerOpen(mDrawerList_Left)){
                         mDrawerlayout.closeDrawer(mDrawerList_Left);
                     }
                     mDrawerlayout.openDrawer(mDrawerList_Right);
                     mDrawerList_Right.bringToFront();
                     mDrawerlayout.requestLayout();
                 }
             });

             RefreshListView();
         }




         // Filling the ArrayLists


         public void RefreshListView() {
             NavDrawerMenuItem[] menu = new NavDrawerMenuItem[]{
                     NavMenuLabel.create("First Label"),
                     NavMenuIconLabel.create("First IconLabel", R.drawable.ic_drawer)
             };
             Left_Adapter = new NavDrawerAdapter(this,R.layout.navdrawer_item,menu);
             mDrawerList_Left.setAdapter(Left_Adapter);

             Right_Adapter = new NavDrawerAdapter(this,R.layout.navdrawer_item,menu);
             mDrawerList_Right.setAdapter(Right_Adapter);

         }

         private  class DrawerItemClickListener implements ListView.OnItemClickListener {

             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                 switch(position) {
                     case 1:
                         Log.d("Item Click","1");
                         break;
                     case 2:
                         Log.d("Item Click","2");
                         break;
                     default:
                 }
             }

         }

activity_main.xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity">

<FrameLayout android:id="@+id/container" android:layout_width="match_parent"
    android:layout_height="match_parent" />

<ListView
    android:id="@+id/drawer_list_left"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:divider="@android:color/transparent"
    android:layout_marginLeft="-64dp"
    android:background="#FFFFFF"/>

<ListView
    android:id="@+id/drawer_list_right"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:divider="@android:color/transparent"
    android:background="#FFFFFF"/>

Community
  • 1
  • 1
Ruben Flores
  • 331
  • 1
  • 3
  • 13
  • You are clicking on item 1 or 2 in the left `ListView` and nothing happens? If you add something to your default case of the switch, does that fire? – MeetTitan Apr 29 '15 at 03:45
  • May be it is case 0 and case 1. also try to print or toast something before switch case. – Harin Apr 29 '15 at 09:36
  • You are right, de first index is 0 and also I was looking in wrong place, he logcat was printing a correct string.. Thanks so much.. – Ruben Flores Apr 29 '15 at 17:58

0 Answers0