0

I want use two Drawer Menu, one of this menus in left and another one of this menus in right. left Drawer Menu is ok, when items clicked, the operation is performed. but in right Drawer Menu, when click on items the operation does not!
My XML code :

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tb="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/DrawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background_color"
        tools:context=".Main_Page">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/viewpagertab">

        </android.support.v4.view.ViewPager>

    </RelativeLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/main_drawer"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/header_menu_app"
        app:itemIconTint="@color/post_card_color"
        app:itemTextColor="@color/post_card_color"
        app:menu="@menu/menu_main__page" />

    <android.support.design.widget.NavigationView
        android:id="@+id/main_drawer2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        app:headerLayout="@layout/header_drawer_main"
        app:itemIconTint="@color/post_card_color"
        app:itemTextColor="@color/post_card_color"
        app:menu="@menu/menu_main_profile" />

</android.support.v4.widget.DrawerLayout>

My JAVA code :

public class Main_Page extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {

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

    // Left DraweLayout Open
        Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);
        mNaviView = (NavigationView) findViewById(R.id.main_drawer);
        mNaviView2 = (NavigationView) findViewById(R.id.main_drawer2);
        mNaviView.setNavigationItemSelectedListener(this);
        mDrawerToggle = new ActionBarDrawerToggle(this, Drawer, toolbar, R.string.openDrawer, R.string.closeDrawer) {

            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                if (con.isOnline()) {
                    new get_menu_info().execute(public_username);
                }
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);

            }
        };
        Drawer.setDrawerListener(mDrawerToggle);
        mDrawerToggle.syncState();

    // Right DraweLayout Open
        ImageView profile_menu = (ImageView) toolbar.findViewById(R.id.right_tool);
        profile_menu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Drawer.openDrawer(mNaviView2);
            }
        });
}

  @Override
    public boolean onNavigationItemSelected(MenuItem menuItem) {
        Intent intent;

        if (menuItem.getItemId() == R.id.menu_action_mySMS) {
            intent = new Intent(this, MySMS_Page.class);
            startActivity(intent);
            overridePendingTransition(R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_top);
            finish();
            return true;
        }

        if (menuItem.getItemId() == R.id.menu_profile_action_favorite) {
            intent = new Intent(this, Fav_Page.class);
            startActivity(intent);
            overridePendingTransition(R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_top);
            finish();
            return true;
        }

        if (menuItem.getItemId() == R.id.menu_action_category) {
            intent = new Intent(this, category_Page.class);
            startActivity(intent);
            overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
            finish();
            return true;
        }

        if (menuItem.getItemId() == R.id.menu_action_setting) {
            intent = new Intent(this, setting_Page.class);
            startActivity(intent);
            overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
            finish();
            return true;
        }

        if (menuItem.getItemId() == R.id.menu_action_about) {
            intent = new Intent(this, about_Page.class);
            startActivity(intent);
            overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
            finish();
            return true;
        }

        if (menuItem.getItemId() == R.id.menu_action_top) {
            intent = new Intent(this, top_Page.class);
            startActivity(intent);
            overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
            return true;
        }

        if (menuItem.getItemId() == R.id.menu_action_free_com) {
            intent = new Intent(this, freeCon_Page.class);
            startActivity(intent);
            overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
            return true;
        }
        return false;
    }
}

Please help me to call right menu items when click on.
tnx <3

ydstsh
  • 183
  • 2
  • 11
  • you can open drawer layout by drawerLayout.openDrawer(GravityCompat.START); // gravity as per your requirement – KishuDroid Oct 31 '15 at 07:27
  • @KishuDroid right menu is open, but not action menu item when clicked. i want click on righr menu items. can you send me true codes? tnx – ydstsh Oct 31 '15 at 07:37

2 Answers2

1

Try this code :

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
     if (item.getItemId() == R.id.menuitemid) {
        if(mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
                        mDrawerLayout.closeDrawer(Gravity.LEFT); // set Gravity as per your need
                    }else{
                        mDrawerLayout.openDrawer(Gravity.LEFT); // set Gravity as per your need
                    }      

    }else if (item.getItemId()== R.id.action_settings) {
        return true;
    } 
    return super.onOptionsItemSelected(item);
}

Hope it will work.

KishuDroid
  • 5,411
  • 4
  • 30
  • 47
  • tnx. i use this code : @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.menu_profile_action_favorite) { Toast.makeText(getApplicationContext(),"t", Toast.LENGTH_SHORT).show(); } else if (item.getItemId()== R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } but not work for me :( – ydstsh Oct 31 '15 at 08:09
  • @Glad to help you buddy. – KishuDroid Oct 31 '15 at 09:07
  • @ KishuDroid , ok sir ;) – ydstsh Oct 31 '15 at 09:51
0

Try this,

@Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.lnrLytMenuSlider:
                switchSliderLeft();
                break;
        }
}

call this method,

public void switchSliderLeft()  {
        getSlidingMenu().showMenu();
        getSlidingMenu().setMode(SlidingMenu.LEFT);
}
Parth Bhayani
  • 1,894
  • 3
  • 17
  • 35
  • tnx but i want click on right menu items. right menu opening but not action when click on right menu items! i want click on right menu items. can you send me true code? tnx – ydstsh Oct 31 '15 at 07:41
  • If you open slider menu after that if you have added items to your sliding menu, it will be open when clicking in it. – Parth Bhayani Oct 31 '15 at 07:48
  • try this, http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/ – Parth Bhayani Oct 31 '15 at 08:12