1

I have two types of users: Guard and Resident. Both of them have different functionalities and hence I want two navigation activities which I can intent after login depending upon user type. But when I try to create second navigation activity it pops up an error because files with the same names already exist. How can I do this?
Is there any other way of achieving this? Any help would be wonderful.
Thanks for your time :)

Vid
  • 123
  • 11
  • Possible duplicate of [Two Navigation Drawer on same Activity](https://stackoverflow.com/questions/29921274/two-navigation-drawer-on-same-activity) – majid ghafouri Sep 29 '19 at 19:59

3 Answers3

1

In your xml, you can use a FrameLayout as a container

   <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true">

        <FrameLayout
            android:id="@+id/contDrawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.design.widget.NavigationView>

Now in your Activity, you can replace it with any fragment

   getSupportFragmentManager().beginTransaction().replace(R.id.contDrawer, SideBarCustomerFragment.newInstance()).commit();

Now for two users, you can create 2 different fragments, You can check my boilerplate code for reference

https://github.com/hamzaahmedkhan/AndroidStructure/blob/master/app/src/main/java/com/android/structure/activities/HomeActivity.java

https://github.com/hamzaahmedkhan/AndroidStructure/blob/master/app/src/main/java/com/android/structure/activities/BaseActivity.java

Hamza Khan
  • 1,433
  • 13
  • 19
1

The easiest way is to add recyleview and add the items you want depending on the user type this will help you to have multiple view types and will support in feature many views and many items now the trick is in the view types in the adapter you can create generic abstract adapter and add the data every item is for sure extended from the generec item but the type is deferent so it will inflat a new view holder now the finel result will be an adapter accept any item extended from generic item class if you want my advice you can just use fast adapter from mikebinz library link below

https://github.com/mikepenz/FastAdapter

Or use the side menu he have more easy to use

https://github.com/mikepenz/MaterialDrawer

Ahmad Najar
  • 66
  • 1
  • 4
1

You can add drawer layout and create two frame layouts and one is gravity start and other is gravity end or you can use this library is very easy and useful and it use fast adapter alos

https://github.com/mikepenz/MaterialDrawer

Ahmad Najar
  • 66
  • 1
  • 4