NavDrawer using activities instead of fragments

0

I'm trying to deploy a NavDrawer in my app but #

Part of the code that uses Fragments:

private void displayView(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;
    switch (position) {
    case 0:
        fragment = new HomeFragment();
        break;
    case 1:
        fragment = new FindPeopleFragment();
        break;
    case 2:
        fragment = new PhotosFragment();
        break;
    case 3:
        fragment = new CommunityFragment();
        break;
    case 4:
        fragment = new PagesFragment();
        break;
    case 5:
        fragment = new WhatsHotFragment();
        break;

    default:
        break;
    }

    if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.frame_container, fragment).commit();

        // update selected item and title, then close the drawer
        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(navMenuTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);
    } else {
        // error in creating fragment
        Log.e("MainActivity", "Error in creating fragment");
    }
}

I would like to know if I can get NavDrawer to work with Activity or if I can convert the activities I have to Fragment (it should be very difficult) so I can deploy NavDrawer in my app.

Thank you in advance.

    
asked by anonymous 24.01.2015 / 02:48

1 answer

3

Unfortunately it is not possible to implement a NavigationDrawer using activities the way you want it. In reality, what you can do is to trigger intents to start your Activities when a NavigationDrawer item is clicked. But I think the behavior is not going to be what you want.

Having said that, I suggest you then turn your activities into fragments. In fact, before you create an activity, always ask yourself if you really need it and / or you can not trade it for a snippet. Fragments are very powerful and help you to modularize and reuse application components.

    
24.01.2015 / 05:50