2

我已经解决了我的问题,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();
4

2 回答 2

3

您必须在一次调用方法中指定整个文本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");

如果您使用该方法两次或更多次,则只会显示上次调用中设置的文本。

于 2013-08-28T21:40:34.673 回答
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();
于 2013-08-28T23:12:25.113 回答