下面的类在Test.java文件中,我想从公共类Test的函数中调用它。
现在我不知道如何访问该功能来显示alertdialog
。我的意思是如何从另一种方法访问下面类的onCreateDialog(Bundle savedInstanceState)
?
以下代码是从this source
复制的 class MyCustomDialog extends DialogFragment{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(inflater.inflate(R.layout.notification_list_layout, null))
// Add action buttons
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// sign in the user ...
}
})
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MyCustomDialog.this.getDialog().cancel();
}
});
return builder.create();
}
}
我想要这样的东西
答案 0 :(得分:3)
MyCustomDialog custDialog = new MyCustomDialog();
custDialog.show(custDialog.getFragmentManager(), "Info");
答案 1 :(得分:0)
我认为这应该有效MyCustomDialog custDialog = new MyCustomDialog();
custDialog.show(manager, tag)