如何用FragmentActivity替换Fragment

时间:2013-12-02 23:43:59

标签: android android-fragments replace fragment android-fragmentactivity

我正在尝试从另一个FragmentActivity(而不是Fragment)加载FragmentActivity,但是收到错误。有没有办法实现这个目标?

@SuppressLint("NewApi")
private void displayView(int position) {
    if (getSupportFragmentManager().findFragmentByTag(Tab_Day.TAG) == null) {
        getSupportFragmentManager().beginTransaction()
            .replace(android.R.id.content, fragmentAct, Tab_Day.TAG).commit();
        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(navMenuTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);
    }

}

这是我得到的错误:

The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, FragmentActivity, String)

1 个答案:

答案 0 :(得分:4)

FragmentActivity不是Fragment的子类,而是Activity的子类。如果您尝试开始新活动,则使用startActivity(Intent intent),否则fragmentAct应为Fragment

它们不可互换。 FragmentActivity个人Fragment s。