Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. how to add a button in one the navigation drawer fragment so that when the user click he is directed to another sub fragment of that previous fragment

how to add a button in one the navigation drawer fragment so that when the user click he is directed to another sub fragment of that previous fragment

Scheduled Pinned Locked Moved Android
tutorialandroidcomdesigndocker
2 Posts 2 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    George S Mulbah II
    wrote on last edited by
    #1

    how to add button in the of the menu item fragment of the navigation drawer so that when the user click on the button he is redirected to anther sub fragment but one issue here is I am using the android custom navigation drawer implementation below is my try

    package com.example.entertainmentlab.ui.store;

    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ImageView;
    import android.widget.TextView;
    import android.widget.Toast;
    
    import androidx.annotation.NonNull;
    import androidx.annotation.Nullable;
    import androidx.fragment.app.Fragment;
    import androidx.fragment.app.FragmentManager;
    import androidx.fragment.app.FragmentTransaction;
    import androidx.lifecycle.Observer;
    import androidx.lifecycle.ViewModelProviders;
    
    import com.example.entertainmentlab.R;
    import com.example.entertainmentlab.ui.setting.SettingViewModel;
    
    public class StoreFragment extends Fragment {
    
        private StoreViewModel StoreViewModel;
    
        public View onCreateView(@NonNull LayoutInflater inflater,
                                 ViewGroup container, Bundle savedInstanceState) {
            StoreViewModel =
                    ViewModelProviders.of(this).get(StoreViewModel.class);
            View root = inflater.inflate(R.layout.fragment\_store, container, false);
           final ImageView MusicButton = root.findViewById(R.id.music\_btn);
    
    
    
    
    
    
    
            MusicButton.setOnClickListener(new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                   try {
    
                       Fragment fragment = new BlankFragment();
                       FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
                       FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                       fragmentTransaction.replace(R.id.nav\_host\_fragment\_container, fragment);
                       fragmentTransaction.addToBackStack(null);
                       fragmentTransaction.commit();
                   }catch (Exception e ){
                       Toast.makeText(getActivity(), "erro  "+e, Toast.LENGTH\_SHORT).show();
                   }
               }
           });
    //        StoreViewModel.getText().observe(getViewLifecycleOwner(), new Observer() {
    /
    
    D 1 Reply Last reply
    0
    • G George S Mulbah II

      how to add button in the of the menu item fragment of the navigation drawer so that when the user click on the button he is redirected to anther sub fragment but one issue here is I am using the android custom navigation drawer implementation below is my try

      package com.example.entertainmentlab.ui.store;

      import android.os.Bundle;
      import android.view.LayoutInflater;
      import android.view.View;
      import android.view.ViewGroup;
      import android.widget.ImageView;
      import android.widget.TextView;
      import android.widget.Toast;
      
      import androidx.annotation.NonNull;
      import androidx.annotation.Nullable;
      import androidx.fragment.app.Fragment;
      import androidx.fragment.app.FragmentManager;
      import androidx.fragment.app.FragmentTransaction;
      import androidx.lifecycle.Observer;
      import androidx.lifecycle.ViewModelProviders;
      
      import com.example.entertainmentlab.R;
      import com.example.entertainmentlab.ui.setting.SettingViewModel;
      
      public class StoreFragment extends Fragment {
      
          private StoreViewModel StoreViewModel;
      
          public View onCreateView(@NonNull LayoutInflater inflater,
                                   ViewGroup container, Bundle savedInstanceState) {
              StoreViewModel =
                      ViewModelProviders.of(this).get(StoreViewModel.class);
              View root = inflater.inflate(R.layout.fragment\_store, container, false);
             final ImageView MusicButton = root.findViewById(R.id.music\_btn);
      
      
      
      
      
      
      
              MusicButton.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View v) {
                     try {
      
                         Fragment fragment = new BlankFragment();
                         FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
                         FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                         fragmentTransaction.replace(R.id.nav\_host\_fragment\_container, fragment);
                         fragmentTransaction.addToBackStack(null);
                         fragmentTransaction.commit();
                     }catch (Exception e ){
                         Toast.makeText(getActivity(), "erro  "+e, Toast.LENGTH\_SHORT).show();
                     }
                 }
             });
      //        StoreViewModel.getText().observe(getViewLifecycleOwner(), new Observer() {
      /
      
      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      So what exactly is the problem?

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups