0

アプリで 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);
}

ここでは画面を Fragment のように配置する必要がありますが、画面は Activity になり、最小限のコード変更で Activity から Fragment に移動したいと考えています。どうすればいいですか?

4

2 に答える 2

0

ここで、アクティビティをフラグメントアクティビティに変換してから、ナビゲーションドロワーを 使用できるはずです。サンプルアプリはこちらもご覧ください

于 2013-10-04T08:33:26.907 に答える