9

我在创建对话框时遇到问题。它确实出现了,但里面是空的,只显示了一个空白框。

对话类:

public class SomeDialog extends DialogFragment{

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();

    builder.setView(inflater.inflate(R.layout.somelayout, null));

    return super.onCreateDialog(savedInstanceState);
}
}

在一个活动中,创建一个对象并调用 show 方法:

SomeDialog obj = new SomeDialog();
obj.show(getFragmentManager(), "randomtag");
4

2 回答 2

7
return super.onCreateDialog(savedInstanceState);

您正在返回父方法。你应该返回你自己的 . 改成 :

 return builder.create();
于 2013-01-17T15:42:20.860 回答
0

就我而言,问题出在

public static DialogFragment newInstance(int param) {
    Bundle args = new Bundle();
    args.putInt(EXTRA_PARAM, param);

    DialogFragment fragment = new DialogFragment(); // Here is an error.
    fragment.setArguments(args);
    return fragment;
}

错误的行应替换为

DialogFragment fragment = new YourDialogFragment();
// Or YourDialogFragment fragment = new YourDialogFragment();
于 2016-11-23T19:21:49.790 回答