2012-11-09 28 views
0

我想显示两个按钮的警报:“Reprendre”和“Plus Tard”。我有下面的代码:AlertDialog只显示两个按钮中的一个

alertsyncincomplete = new AlertDialog.Builder(this); 
alertsyncincomplete.setCustomTitle(titleAlertSyncIncomplete); 
alertsyncincomplete.setPositiveButton("Reprendre", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int which) { 

    } 
}); 

alertsyncincomplete.setNegativeButton("Plus tard", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int which) { 

    } 
}); 

但是我能看到的只是屏幕上的一个按钮 - 文本“Reprendre”第一个。我用AlertDialogsetButtonsetButton2方法,我得到了相同的结果。我将文本“Plus Tard”改为“OK”(长度较短),然后显示两个按钮。我认为问题应该与文本的长度有关(即使我按钮上的文本不是很长)。

我该如何解决这个问题?

回答

2

这个工作对我来说:

AlertDialog.Builder builder = new AlertDialog.Builder(YouActivity.this); 
builder.setTitle("title"); 
builder.setMessage("message"); 
builder.setPositiveButton("Reprendere", null); 
builder.setNegativeButton("Plus Tard", null); 
builder.show(); 
0

使用此:

AlertDialog anAlertDialog = new AlertDialog.Builder(getParent()).create(); 
        anAlertDialog.setTitle(""); 
        anAlertDialog.setMessage("Are you sure you want to logout!"); 
        anAlertDialog.setButton("OK", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 

          return; 
         } 
        }); 
        anAlertDialog.setButton2("CANCEL", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 

         } 
        }); 
        anAlertDialog.show(); 
相关问题