AlertDialog不显示两行

时间:2013-08-28 21:31:39

标签: android dialog

我已经用alertDialog.dismiss();问题解决了我的问题,但现在我有一个用我的两行对话框。看到对话框弹出时它只显示这个alertDialog.setMessage("1st line" + System.getProperty("line.separator") + "2nd line");,我也需要它来显示这个alertDialog.setMessage("1st line that doesn't display" + System.getProperty("line.separator") + "2nd line that doesn't display");我真的不明白为什么会这样,所以任何人都可以帮我这个。

final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);

alertDialog.setTitle("ApplicationTitle");
alertDialog.setIcon(R.drawable.ic_launcher);
alertDialog.setMessage("1st line that doesn't display" + System.getProperty("line.separator") + "2nd line that doesn't display");                
alertDialog.setMessage("1st line" + System.getProperty("line.separator") + "2nd line"); 
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog, int which) {

    }
 });

alertDialog.show();

2 个答案:

答案 0 :(得分:2)

您必须在对方法setMessage的一次调用中指定整个文本:

alertDialog.setMessage("1st line that doesn't display"
            + System.getProperty("line.separator")
            + "2nd line that doesn't display"
            + System.getProperty("line.separator") + "1st line"
            + System.getProperty("line.separator") + "2nd line");

如果您使用该方法两次或更多次,则仅显示最后一次通话中设置的文本。

答案 1 :(得分:0)

     StringBuilder build = new StringBuilder();
     build.append("1st line")
     .append("\n")
     .append("2nd line")
     .append("\n")
     .append("3rd line");

final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);

alertDialog.setTitle("ApplicationTitle");

alertDialog.setMessage(build.toString());     


alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog, int which) {
        dialog.cancel();
    }
 });
alertDialog.show();