显示多行文本和变量在AlertDialog使用setMessage() [英] Displaying multiple lines of text and variables in an AlertDialog using setMessage()

查看:3897
本文介绍了显示多行文本和变量在AlertDialog使用setMessage()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在一个警告对话框显示多行文本。如果使用多个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);   

这篇关于显示多行文本和变量在AlertDialog使用setMessage()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆