从片段打开 DialogFragment - FragmentManager 出错
Open DialogFragment from a Fragment - Error with FragmentManager
嘿,我目前正在尝试将 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;
出现以下错误:无法解析 methode show(android.app.FragmentManager, java.lang.string)
是的,我知道这个问题已经存在,但解决方案对我不起作用:/
我的 DialogFragment:
public class 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;
} }
如果您需要项目中的更多代码,我会添加它
感谢您的帮助和问候
您的 DialogWeightConverter
从 android.support.v4.app.DialogFragment
延伸?试试 getActivity().getSupportFragmentManager()
嘿,我目前正在尝试将 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;
出现以下错误:无法解析 methode show(android.app.FragmentManager, java.lang.string)
是的,我知道这个问题已经存在,但解决方案对我不起作用:/
我的 DialogFragment:
public class 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;
} }
如果您需要项目中的更多代码,我会添加它
感谢您的帮助和问候
您的 DialogWeightConverter
从 android.support.v4.app.DialogFragment
延伸?试试 getActivity().getSupportFragmentManager()