2012-10-12 33 views
0

如果在java控制台中很容易就使用printf,但是我对android很陌生,如何创建列来对齐对话框中的字符串?在android对话框中格式化

例如:

public void onAlert() { 
     new AlertDialog.Builder(MainActivity.this) 
     .setTitle("Completed! Workout log: ") 
       .setMessage("Date: " + date + "\n" + 
        "Item : " + item + "\n" + 
        "Price: " + price + "\n" + 
        "Value: " + value + "\n") 

       .setPositiveButton("OK", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 

      } 
     }) 
     .show(); 

我想实现这一点:

enter image description here

回答

1

选项A(脏):收到警报文本视图,并设置一个固定大小的字体

选项B(清洁):使用自定义视图和桌面布局(请参阅http://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout

+0

谢谢!我可以问一个新手问题吗? setView有什么作用? –

+0

(我发布的链接的第一行),“将[布局]添加到AlertDialog” – njzk2