Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android AlertDialog到DialogFragment_Android_Dialog - Fatal编程技术网

Android AlertDialog到DialogFragment

Android AlertDialog到DialogFragment,android,dialog,Android,Dialog,确定类型活动中的showDialog(int,Bundle)方法已被弃用。。。因此,我已经将计时器选择器更改为fragmentDialog,这非常简单,因为fragmentDialog已经准备好: new TimePickerDialog(getActivity(),_listener, _hour, _minute,dateFormat); 但是我怎样才能重新制作这种类型的对话框 AlertDialog.Builder .setIcon() .setTitle

确定类型活动中的showDialog(int,Bundle)方法已被弃用。。。因此,我已经将计时器选择器更改为fragmentDialog,这非常简单,因为fragmentDialog已经准备好:

new TimePickerDialog(getActivity(),_listener, _hour, _minute,dateFormat);
但是我怎样才能重新制作这种类型的对话框

AlertDialog.Builder
        .setIcon()
        .setTitle()
        .setPositiveButton()
        .setSingleChoiceItems(new CharSequence[]{"Visual","Audio","Both"},2,null)

谢谢。

如果我理解正确,您希望重用
AlerDialog
,这样您就可以定义一次,并在片段/活动的不同位置使用它

从android文档
AlertDialog android.app.AlertDialog.Builder.create()
使用提供给此生成器的参数创建AlertDialog。它不显示()对话框。这允许用户在显示对话框之前进行任何额外的处理。如果您没有任何其他处理要做,并且希望创建和显示该处理,请使用show()。
So:

//declare inside your fragment class
private AlertDialog welcomeDialog;

//Inisde onCreate paste the following code so your dialoge is just created but not shown
            welcomeDialog = new AlertDialog.Builder(this)
                .setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(
                        getResources().getString(R.string.first_run_title))
                .setMessage(
                        getResources().getString(R.string.first_run_desc))
                .setPositiveButton(R.string.ok,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                dialog.dismiss();
                            }
                        }).create();

//Wherever in your code you need to display the dialog,just use this piece of code:
welcomeDialog.show();

//and finally to do the cleanup:
    @Override
protected void onStop() {
    super.onStop();
    if (welcomeDialog != null)
        welcomeDialog.dismiss();}

无法理解:
如何将大量此类对话框以相同的布局重新制作成碎片对话框?
是否要在DialogFragmnet中显示单个选定的AlertDialog?我更改了问题。希望这更清楚,现在还不清楚。据我所知,您不想使用
showDialog
,而是想在
DialogFragment
中使用
AlertDialog.Builder.setIcon().setTitle().setPositiveButton().setSingleChoiceItems(新的字符序列[]{“视觉”、“音频”、“两者”},2,null)
,我说的对吗?Shajeel Afzal-是的,你理解的对。这个人没有回答,所以我没有回答他的问题。请回答,因为这可能对我有帮助,而其他人我没有回答什么?我这里的东西(关于AlertDialog的部分)是我答案的一部分。当我将所有对话框重新制作成AlerDialogs时,我会发布代码和answare来回答我的问题。