【问题标题】:custom alert box in androidandroid中的自定义警报框
【发布时间】:2013-01-17 06:29:43
【问题描述】:

下面的类在文件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();
    }

}

我想要这样的东西

【问题讨论】:

  • 我被困在这里了。只是不知道如何访问它
  • 不确定您的问题,但stackoverflow.com/a/8311800/1777090 可能会有所帮助
  • 我不知道如何访问 MyCustomDialog 类的 onCreateDialog(Bundle savedInstanceState) 以便我可以弹出上面定义的警报框
  • 好的。参考这个。 arusahni.net/blog/2012/01/… 。自定义 dialogfragment 类中有方法 newInstance()。所以你可以使用它,我想
  • 不清楚你的问题可以请你发给我你想在自定义对话框中显示什么。

标签: java android android-alertdialog


【解决方案1】:
MyCustomDialog custDialog = new MyCustomDialog();
custDialog.show(custDialog.getFragmentManager(), "Info"); 

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2015-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多