Android - Navigation drawer fragments

后端 未结 3 1614
粉色の甜心
粉色の甜心 2021-01-06 12:24

I have implemented navigation drawer in my android app. but now I want to be able to change the layout using fragments when the user clicks any list item in the navigation b

3条回答
  •  离开以前
    2021-01-06 12:30

    On click have

      selectItem(pos);
    

    Then

    public void selectItem(int position)
    {
         switch(position)
         {
              case 0:
                         // fragment1
                         // use fragment transaction and add the fragment to the container
                         FragmentManager fragmentManager = getFragmentManager()
                         FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();   
                         Fragment1 fragment = new Fragment1();
                         fragmentTransaction.add(R.id.content_frame, fragment);
                         fragmentTransaction.commit();
    
              break;
              case 1:
                         // fragment2
              break; 
              case 2:
                         // fragment2
              break;
         } 
    }
    

提交回复
热议问题