2012-10-12 34 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