我尝试从 Android 文档制作 Dialog
public class FireMissilesDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.dialog_fire_missiles)
.setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
下面我们可以读到这样的内容:
现在,当您创建此类的实例并在该对象上调用 show() 时,将出现如图 1 所示的对话框。
但是,当我尝试从我的主要活动创建一个对话框时:
FireMissilesDialogFragment myDialog = new FireMissilesDialogFragment();
myDialog.???
我show()
在 myDialog 上没有方法:|
怎么了 ?
这在您的主要活动中:
new FireMissilesDialogFragment().show(getFragmentManager(), "dialog");
用于显示您的对话框
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句