启动片段活动NavigationDrawer

时间:2014-03-31 15:42:24

标签: android android-fragments android-activity android-fragmentactivity navigation-drawer

我正在NaviagationDrawer使用Fragment。现在在MainActivity中,我打开了各种片段,但其中一行必须打开FragmentActivity

/**
 * Diplaying fragment view for selected nav drawer list item
 * */
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 InFragment();
        break;
    case 2:
        fragment = new RiFragment();
        break;
    case 3:
        fragment = new RieFragment();
        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");
    }
}

我想将案例1更改为片段活动我该怎么办?

1 个答案:

答案 0 :(得分:0)

如果一个FragmentActivity

,请使用意图打开
...
     case 0:
            fragment = new HomeFragment();
            break;
        case 1:
            Intent intent = new Intent(getApplicationContext(), myFragmentActivity.class);
            startActivity(intent);
        case 2:
            fragment = new RiFragment();
            break;
...