我正在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更改为片段活动我该怎么办?
答案 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;
...