2016-01-29 84 views
0

我做了一些我可以用Toast顯示的字符串,但我很難弄清楚如何讓它們與單個Toast同時出現。到目前爲止,我有這個:如何將多個字符串顯示爲一個Toast?

String text = input.getText().toString(); 
String text2= input2.getText().toString(); 
String text3 = input3.getText().toString(); 
Toast.makeText(getApplicationContext(),"Name: " + text,Toast.LENGTH_SHORT).show(); 
Toast.makeText(getApplicationContext(),"Age: " + text2,Toast.LENGTH_SHORT).show(); 
Toast.makeText(getApplicationContext(),"Occupation: " + text3,Toast.LENGTH_SHORT).show(); 

當我運行模擬器時,它一次顯示一個Toasts。有沒有辦法同時顯示姓名,年齡和職業?

回答

3

將它們連接在一起。

Toast.makeText(getApplicationContext(), 
     "Name: " + text 
    + " Age: " + text2 
    + " Occupation: " + text3, 
    Toast.LENGTH_SHORT).show(); 
1

嘗試這種情況:

Toast.makeText(this, "data = " +t_amount+ "" +order_no+ "" +ph_no, Toast.LENGTH_SHORT).show(); 
0

嘗試

String data = "Name: " + text + "\n" + " Age: " + text2 + "\n" + " Occupation: " + text3; 
Toast.makeText(getApplicationContext(), data, Toast.LENGTH_LONG).show(); 
+0

或字符串數​​據=的String.Format(「姓名:{0} \ NAGE:{1} \ nOccupation:{2} 「,text,text2,text3);或者在C#6中使用插值字符串String data = $「Name:{text} \ nAge:{text2} \ nOccupation:{text3}」; – PaulF

相關問題