我需要在一个警告对话框显示多行文本。如果使用多个setMessage()方法,只显示上一次setMessage,如下所示。
I need to display multiple lines of text in an Alert Dialog. If I use multiple setMessage() methods, only the last setMessage is displayed, as shown below.
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Statistics:");
alertDialog.setMessage("No. of attempts: " + counter);
alertDialog.setMessage("No. of wins: " + counterpos);
alertDialog.setMessage("No. of losses: " + counterneg);
有没有一种方法来创建对话框中每一项新行?像使用\ n个System.print.out();方法。
Is there a way to create a new line for each of these in the dialog? Like using \n in System.print.out(); method.
谢谢!
您可以做这样的事情
String alert1 = "No. of attempts: " + counter;
String alert2 = "No. of wins: " + counterpos;
String alert3 = "No. of losses: " + counterneg;
alertDialog.setMessage(alert1 +"\n"+ alert2 +"\n"+ alert3);