从片段打开DialogFragment - FragmentManager出错

时间:2015-10-13 17:27:05

标签: android android-fragments alertdialog android-dialogfragment dialogfragment

嘿,我目前正尝试将DialogFragment添加到Fragment中。它应该在我单击TextView时打开:

片段:

public class FragmentOneRm extends Fragment {



 @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    myContext = (main_container)this.getActivity();

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { mTextViewMaxWeight.setOnLongClickListener(new View.OnLongClickListener() {
 //other code         
        @Override
        public boolean onLongClick(View v) {
            DialogWeightConverter dialog = DialogWeightConverter.newInstance();
       // Problem with getFragmentManager() 
            dialog.show(getFragmentManager(), "fragmentDialog");

        }
    });


    return view; 

出现以下错误:无法解析方法显示(android.app.FragmentManager,java.lang.string)

是的,我知道这个问题已经存在,但解决方案并不适用于我:/

我的DialogFragment:

公共类DialogWeightConverter扩展了DialogFragment {

Context mContext;

public DialogWeightConverter() {
    mContext = getActivity();
}


@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    Dialog dialog = builder.create();

    return dialog;
}

public static DialogWeightConverter newInstance() {
    DialogWeightConverter f = new DialogWeightConverter();
    return f;
} }

如果你需要来自Project i的更多代码,我会添加它

感谢您的帮助和问候

1 个答案:

答案 0 :(得分:1)

您的DialogWeightConverter是否来自android.support.v4.app.DialogFragment?试试getActivity().getSupportFragmentManager()