Navigation Drawer Doesn't Show Fragments
Solution 1:
Make the drawer's list in Your activity and add setOnItemClickListener().When the user selects an item in the drawer's list, the system calls onItemClick() on the OnItemClickListener given to setOnItemClickListener().
What you do in the onItemClick() method depends on how you've implemented your app structure. In the following example, selecting each item in the list inserts a different Fragment into the main content view (the FrameLayout element identified by the R.id.content_frame ID): for more delail please read these articles youtube and github example
Solution 2:
Latest - If you use Navigation Architecture Component, then you don't have to manually connect your fragments to your drawer MenuItem. The system will automatically tie you MenuItem to specific fragment
If the id of the MenuItem in your menu/xyz_menu.xml
matches the id of the destination in navigation/xyz_nav.xml
, the NavController can then navigate to that destination.
Follow the correct steps mentioned in the official documentation : https://developer.android.com/guide/navigation/navigation-ui#Tie-navdrawer
Note :
They have a sample app linked to the same article which you can refer.
To get this is effect, do not implement
onNavigationItemSelected
otherwise it will override the system let you handle the navigation.
Post a Comment for "Navigation Drawer Doesn't Show Fragments"