0

我有一个名为 HomeActivity 的活动,

{
public class HomeActivity extends SherlockFragmentActivity
}

但是下面的代码

{


    private void selectItem(int position) {

        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        // Locate Position
        switch (position) {
        case 0:
            ft.replace(R.id.content_frame, home);
            break;
        case 1:
            ft.replace(R.id.content_frame, gadget);
            break;
        case 2:
            ft.replace(R.id.content_frame, news);
            break;
        case 3:
            ft.replace(R.id.content_frame, techno);
            break;
        case 4:
            ft.replace(R.id.content_frame, game);
            break;
        case 5:
            ft.replace(R.id.content_frame, tips);
            break;
        case 6:
            ft.replace(R.id.content_frame, cgt);
            break;
        case 7:
            ft.replace(R.id.content_frame, info);
            break;
        }
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.commit();
        mDrawerList.setItemChecked(position, true);
        // Close drawer
        mDrawerLayout.closeDrawer(mDrawerList);

    }
}

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

FragmentTransaction 无法替换我在 SherlockFragmentActivity 中的片段。

我对此一无所知,我从 google 和 stackoverflow 搜索并实现了一些方法,但我的问题仍然不是那么请我需要这个提示..谢谢

4

1 回答 1

0

当使用 ActionBarSherlock 和 Google 支持库等兼容性框架时,很容易将导入与本机 API 混为一谈。

以 FragmentTransaction 类为例。

确保您没有导入本机版本。

import android.app.FragmentTransaction;

相反,请确保从支持库中导入版本。

import android.support.v4.app.FragmentTransaction;

实际检查您在项目中使用的所有导入,确保选择正确的导入 (support.v4.app)。

于 2013-09-06T06:32:29.207 回答