/**
* Diplaying fragment view for selected nav drawer list item
* */
private void displayView(int position) {
// update the main content by replacing fragments
FragmentActivity fragment = null;
switch (position) {
case 0:
fragment = new HomeFragment();
break;
case 1:
fragment = new HomeFragment();//LessonPlanFragment();
break;
case 2:
fragment = new HomeFragment();//GradeBookFragment();
break;
case 3:
fragment = new HomeFragment();//StudentFragment();
break;
case 4:
fragment = new HomeFragment();//ReportsFragment();
break;
case 5:
fragment = new HomeFragment();//AppSettingsFragment();
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getFragmentManager();
android.app.FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.frame_container, fragment);
ft.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");
}
}
我尝试过使用支持库,但没有任何帮助。错误消息“FragtTransaction”中的“het方法替换(int,Fragment)”不适用于参数(int,FragmentActivity)。
答案 0 :(得分:0)
这不起作用。您正尝试将Fragment
替换为FragmentActivity
,这是不可能的。你只能用Fragment
来做到这一点。为澄清FragmetnActivity
充当支持库中碎片的主机活动。