java 在吐司上显示整数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28152958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Displaying integer on toast
提问by Gal Israel
Im trying to display a toast message with integer inside it This is how i tried to do it:
我试图在其中显示一个带有整数的 toast 消息这是我尝试这样做的方式:
Toast.makeText(this,bignum,Toast.LENGTH_LONG).show();
But it keeps crash my app. Thanks for help!
但它让我的应用程序崩溃。感谢帮助!
回答by Mena
Toast.makeText
either takes a CharSequence
or an int
as its second argument.
Toast.makeText
将 aCharSequence
或 anint
作为其第二个参数。
However, the int
represents a resource ID(such as R.string.hello_world
).
但是,int
表示资源 ID(例如R.string.hello_world
)。
The application crashes probably because no resource is found with that ID, since it's not an ID to start with, but an arbitrary integer.
应用程序崩溃可能是因为没有找到具有该 ID 的资源,因为它不是一个 ID,而是一个任意整数。
In your case, use Toast.makeText(this,String.valueOf(bignum),Toast.LENGTH_LONG).show();
.
在您的情况下,请使用Toast.makeText(this,String.valueOf(bignum),Toast.LENGTH_LONG).show();
.
回答by Blackbelt
you need a String
你需要一个 String
Toast.makeText(this, String.valueOf(bignum),Toast.LENGTH_LONG).show();
otherwise android will try to look it up for a String with id bignum
, in your strings.xml file
否则 android 将尝试bignum
在您的 strings.xml 文件中查找带有 id 的 String
回答by Nick
Try this to "cast" bignum to string:
试试这个将 bignum 转换为字符串:
Toast.makeText(this,"" + bignum,Toast.LENGTH_LONG).show();
回答by Ziad H.
You can do this:
你可以这样做:
Toast.makeText(getBaseContext(), "" + bignum, Toast.LENGTH_LONG).show();