Java RoboFragment不适用于方法FragmentTransaction.add(int,Fragment)

Java RoboFragment不适用于方法FragmentTransaction.add(int,Fragment),java,android,android-fragments,guice,roboguice,Java,Android,Android Fragments,Guice,Roboguice,我有 我试着从另一个活动中创建它: public class ItemDetailFragment extends RoboFragment 但我得到了这个错误: public class ItemDetailActivity extends RoboFragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInst

我有

我试着从另一个活动中创建它:

public class ItemDetailFragment extends RoboFragment
但我得到了这个错误:

public class ItemDetailActivity extends RoboFragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_item_detail);

        // Show the Up button in the action bar.
        getActionBar().setDisplayHomeAsUpEnabled(true);

        // savedInstanceState is non-null when there is fragment state
        // saved from previous configurations of this activity
        // (e.g. when rotating the screen from portrait to landscape).
        // In this case, the fragment will automatically be re-added
        // to its container so we don't need to manually add it.
        // For more information, see the Fragments API guide at:
        //
        // http://developer.android.com/guide/components/fragments.html
        //
        if (savedInstanceState == null) {
            // Create the detail fragment and add it to the activity
            // using a fragment transaction.
//            Bundle arguments = new Bundle();
//            arguments.putString(ItemDetailFragment.ARG_ITEM_ID,
//                    getIntent().getStringExtra(ItemDetailFragment.ARG_ITEM_ID));
            ItemDetailFragment fragment = new ItemDetailFragment();
            //fragment.setArguments(arguments);
            getFragmentManager().beginTransaction()
                    .add(R.id.item_detail_container, fragment)
                    .commit();

            fragment.init(getApplicationContext());
        }
    }

据我所见,
RoboFragmentActivity
从支持库扩展了
android.support.v4.app.FragmentActivity


我认为您应该调用
getSupportFragmentManager()
而不是
getFragmentManager()

它停止了编译错误,但现在我看不到任何UI。这是什么原因造成的?在这之前是
公共类itemdailfragment extensed Fragment
实际上,我在最后看到了UI,但看到的速度很慢。2-3秒后。可能是因为另一个代码,我想是的,我看你发布的代码没有问题。
Error:(45, 21) Gradle: error: no suitable method found for add(int,ItemDetailFragment)
method FragmentTransaction.add(int,Fragment,String) is not applicable
(actual and formal argument lists differ in length)
method FragmentTransaction.add(int,Fragment) is not applicable
(actual argument ItemDetailFragment cannot be converted to Fragment by method invocation conversion)
method FragmentTransaction.add(Fragment,String) is not applicable
(actual argument int cannot be converted to Fragment by method invocation conversion)