2015-11-01 30 views
0

举杯我有一个问题,我DialogFragment巢AlertDialog或内部DialogFragment

public class HorairesFragment extends DialogFragment { 

    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
     LayoutInflater i = getActivity().getLayoutInflater(); 
     mView = i.inflate(R.layout.intervention_horaires_fragment, null); 
     AlertDialog.Builder b= new AlertDialog.Builder(getActivity()) 
       .setPositiveButton(R.string.ok, 
         new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int whichButton) { 

          AlertDialog alert = new AlertDialog.Builder(getFragmentManager()) 
          .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { 
           public void onClick(DialogInterface dialog, int id) { 
            dialog.cancel(); 
           } 
          }).create(); 
          alert.setMessage(message); 
          alert.setCancelable(false); 
          alert.show(); 

          } 
         } 
       ) 
       .setNegativeButton(R.string.annuler, 
         new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int whichButton) { 
           dialog.dismiss(); 
          } 
         } 
       ); 
     b.setView(mView); 
     return b.create(); 
    } 
} 

我删除了可读性的代码。下面是

enter image description here

有时用户输入一些不正确的数据,所以当我点击确定按钮,我需要出示带有自定义错误消息的AlertDialog(或吐司也许)我DialogFragment截图。

的问题如下:当他点击OK OK在AlertDialog,它也解雇我的对话框

enter image description here

是否可以纠正的行为呢?

+0

如何在错误对话框之后再次显示对话框? –

+0

警报对话框上的按钮总是关闭警报对话框,这不是第二个对话框的问题。 – njzk2

+0

+ njzk2你是对的。如果我删除第一个DialogFragment上的正面按钮并将其转换为一个按钮。问题已经解决了。我正在寻找像材料对话框中的两个按钮样式.. –

回答

相关问题