Android toast:将 int 附加到字符串会导致换行
我正在尝试显示一条消息,说明用户单击或用手指按下的内容。
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();
}
这将显示(例如按框 4)
您单击了带有多个的内容 4
如何让它在数字前不添加换行符?
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 clicked something with a number of
4
How can I get it to not add a line break before the number?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下
String.format("you clicked blah blah blah %1$d", value)
它总是对我有用。另外,通过这种方式,您可以从 strings.xml 中提取该字符串。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.祝酒词不会在数字之前专门中断。
尝试将您的号码替换为单个“W”,您应该会在“W”之前看到相同的换行符。
三个简单的想法:
- 使用较小的字体来主题化你的Toast
- 缩短短信:“您点击了号码”+...
- 延长文本消息,这样第二行只有一个数字就不会显得奇怪:“您刚刚单击了编号为 4 的项目。谢谢!”
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 !"