Issue
How to handle menu item clicks on NavigationView in Main Activity?
NavigationView navigationView = findViewById(R.id.nav_view);
I am using "Navigation Drawer Activity" template from latest Android Studio (2021.2.1 Patch 2) as a start.
Thanks.
Solution
Here is what I did hope this helps:
DrawerLayout drawerLayout = view.findViewById(R.id.drawerLayout);
view.findViewById(R.id.imageMenu).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
drawerLayout.openDrawer(GravityCompat.START);
}
});
And then it will call this function when drawer button is clicked to open the drawer
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.miItem1){
}
if (id == R.id.miItem2){
FragmentManager fm = getActivity().getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
transaction.replace(R.id.ProfileFragment, fragment);
transaction.commit();
//startActivity(new Intent(getActivity(), PopFragment.class));
}
if (id == R.id.miItem3){
profileOrCoverPhoto = "image";
showImagePicDialog();
}
if (id == R.id.miItem4){
showNamephoneupdate("name");
}
if (id == R.id.miItem5){
showPasswordChangeDailog();
}
if (id == R.id.miItem7){
firebaseAuth.signOut();
startActivity(new Intent(getActivity(), SplashScreen.class));
getActivity().finish();
}
if (id == R.id.miItem8){
showdeleteaccountdialog();
}
return true;
}
Answered By - Lucas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.