0

我在我的应用程序中提供了NavigationDrawer。使用手动在NavigationDrawer模式上移动的最佳方式是什么?

我'上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); 
} 

在这里,我必须把我的屏幕像碎片,但现在我的屏幕是活动的,我想从我的活动而移动用最少的代码改变片段。我能做什么?

回答

2

它只是改变从活动延伸到片段中的最佳解决方案,改变的onCreate()来onActivityCreated()和移动layout.xml连接上onCreateView()

0

请参阅here 您应该可以将您的活动转换为碎片活动,然后使用导航抽屉。另请参阅here的示例应用程序

+0

你不undarstand问题。将MainActivity从Activity转换为FragmentActivity或ActionBarActivity不是问题。在Fragment中重写NotMainActivity(将在NavigationDrawer中填充的内容)中的问题。 –

相关问题