0

下面的类在文件 Test.java 中,我想从公共类 Test 的函数中调用它。现在我不知道如何访问该功能以显示alertdialog. 我的意思是如何onCreateDialog(Bundle savedInstanceState)从另一种方法访问下面的类?

下面的代码是从这个源复制的

  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();
    }

}

我想要这样的东西 在此处输入图像描述

4

2 回答 2

3
MyCustomDialog custDialog = new MyCustomDialog();
custDialog.show(custDialog.getFragmentManager(), "Info"); 
于 2013-01-17T11:14:00.913 回答
0

我认为这应该有效MyCustomDialog custDialog = new MyCustomDialog(); custDialog.show(manager, tag)

于 2013-01-17T06:52:14.033 回答