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中填充的內容)中的問題。 –

相關問題