0

I provide NavigationDrawer in my app.

I'am using manual on http://developer.android.com/training/implementing-navigation/nav-drawer.html

/**
 * Swaps fragments in the main content view
 */
private void selectItem(int position) {
    // Create a new fragment and specify the planet to show based on
    // position
    Fragment fragment = new PlanetFragment();
    Bundle args = new Bundle();
    args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
    fragment.setArguments(args);
    // Insert the fragment by replacing any existing fragment
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
    // Highlight the selected item, update the title, and close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mPlanetTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

Here I must put my screen like Fragment, but now my screen is Activity, and I want to move from my Activity to Fragment with minimal code change. What can I do this?

gunar
  • 14,660
  • 7
  • 56
  • 87
Konstantin.Efimenko
  • 1,242
  • 1
  • 14
  • 38

2 Answers2

2

The best solution it's just change extending from Activity to Fragment, change onCreate() to onActivityCreated() and move layout.xml linking on onCreateView()

Konstantin.Efimenko
  • 1,242
  • 1
  • 14
  • 38
0

See here you should be able to convert your activity to a fragmentactivity and Then use the navigation drawer. Also see here for sample app

Community
  • 1
  • 1
Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43
  • You don't undarstand question. It's not a problem to convert MainActivity from Activity to FragmentActivity or ActionBarActivity. Problem in rewritting NotMainActivity (what will be populated in NavigationDrawer) in Fragment. – Konstantin.Efimenko Oct 04 '13 at 08:44