0

我对 SherlockFragment 有疑问。如果我用“Fragment”更改“extends SherlockFragment”,效果很好。但是当和夏洛克一起工作时,我会这样工作。

这段代码是一个片段:

import com.actionbarsherlock.app.SherlockFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


public class Box extends SherlockFragment {

    public Box(){}

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.box, container, false);
        return rootView;
    }
}

在我的 ActivityMain.java 我有这个:

SherlockFragment fragment = null;

它适用于 Fragment fragment = null;

我称之为:

fragment= new Box();

但问题是这段代码中的 .replace :

 FragmentManager fragmentManager = getFragmentManager();
 fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
4

1 回答 1

1

change the getFragmentManager to getSupportFragmentManager for using sherlockfragment

FragmentManager fragmentManager = getSupportFragmentManager();
 fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
于 2014-03-10T14:00:06.327 回答