我对碎片有意见。
我面临的问题是,我有一个简单的DialogFragment

public class Fragment3 extends DialogFragment  {
private Fragment activity;
ViewGroup root;

static Fragment3 newInstance() {
    Fragment3 f = new Fragment3();
    return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    root = (ViewGroup) inflater.inflate(R.layout.fragment3_layout, container, false);
    return root;
  }
}

我想从另一个片段创建这个片段
public class ListViewImageAdapter extends BaseAdapter {

private Fragment activity;
....

public ListViewImageAdapter(Fragment activity, ArrayList<Object> listImages) {
    this.activity = activity;
 ...}

....
FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
Fragment3 newFragment = Fragment3.newInstance();
newFragment.show( ft, "dialog");
....

但我得到一个信息:
The method show(FragmentManager, String) in the type DialogFragment is not applicable for the arguments (FragmentTransaction, String)

最佳答案

import android.support.v4.app.FragmentActivity;

而不是:
import android.app.DialogFragment;

(或相反)

07-27 22:36