我已经解决了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();
最佳答案
您必须在对方法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");
如果使用此方法两次或更多次,则仅显示在上次调用中设置的文本。