'是'按钮不显示在Android应用程序的确认框中?

问题描述:

喜的朋友我设定是一个对话框,没有按钮,但只有NO是可见的是按钮是不可见的,请建议我'是'按钮不显示在Android应用程序的确认框中?

这是我事先用感谢

 alertDialog.setButton("YES", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog,int which) { 

       // Write your code here to invoke YES event 
       Toast.makeText(getApplicationContext(), "You clicked on YES", Toast.LENGTH_SHORT).show(); 
       } 
      }); 

      // Setting Negative "NO" Button 
    alertDialog.setButton("NO bad", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int which) { 
       // Write your code here to invoke NO event 
       Toast.makeText(getApplicationContext(), "You clicked on NO", Toast.LENGTH_SHORT).show(); 
       dialog.cancel(); 
       } 
      }); 
+0

如果这实际上是一个AlertDialog,请使用正负按钮。 – CommonsWare

+0

它显示错误,如果我使用正面和负面 – Vji

+1

它显示什么错误? – Piyush

我THI你应该遵循下面给出的这个Builder模式的例子。

AlertDialog.Builder builder = new AlertDialog.Builder(context) 
     .setCancelable(true) 
     .setTitle(titleResourceId) 
     .setMessage(messageResourceId) 
     .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 

      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       Toast.makeToast(mContext, "Yes", Toast.LENGTH_SHORT).show(); 
       dialog.dismiss(); 
      } 
     }).setNegativeButton("No", new DialogInterface.OnClickListener() { 

      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       Toast.makeToast(mContext, "No", Toast.LENGTH_SHORT).show(); 
      } 
     }); 
    builder.show(); 

使用setPositiveButton()setNegativeButton()允许Android根据应用程序在运行平台上放置的按钮按正确的顺序。

+1

是的,我非常感谢你... – Vji

,而不是

代码
alertDialog.setButton 

使用

alertDialog.setPositiveButton 
alertDialog.setNegativeButton 

而不是

setButton() 

使用setPositiveButton()为“是”, setNegativeButton()为“否”