开发者

Android toast: appending int to string causes line break

开发者 https://www.devze.com 2023-02-06 04:31 出处:网络
I\'m trying to display a message stating what the user clicked, or pressed with their finger. public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

I'm trying to display a message stating what the user clicked, or pressed with their finger.

public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
   Toast.makeText(layout_4.this, "you clicked something with a number of " + Integer.toString(value), Toast.LENGTH_SHORT).show();
}

This displays (with say pressing box 4)

you click开发者_Python百科ed something with a number of 4

How can I get it to not add a line break before the number?


Give a shot to String.format("you clicked blah blah blah %1$d", value) it always works for me. Plus this way you make it possible to pull that String from the strings.xml.


Toasts do not specifically break before a number.

Try replacing your number with a single 'W' and you should see the same line break before the 'W'.

Three simple ideas : - Theme your Toast using a smaller font size - Shorten the text message : "You clicked number " + ... - Lengthen the text message so that it doesn't look weird to have only a number on the second line : "You have just clicked on the item numbered 4. Thank you !"

0

精彩评论

暂无评论...
验证码 换一张
取 消