机器人 - 如何将INT转换为字符串,并将其放置在一个的EditText?
问题描述:
我有这块code:
ed = (EditText) findViewById (R.id.box);
int x = 10;
ed.setText (x);
这原来是一个错误。我知道我必须将它更改为字符串,但如何做到这一点?
It turns out to be an error. I know I have to change it to string, but how do I do this?
我已经试过 x.toString()
,但不能进行编译。
I've tried x.toString()
, but it can't be compiled.
答
使用 +
的的string串联运营商:
ed = (EditText) findViewById (R.id.box);
int x = 10;
ed.setText(""+x);
或使用String.valueOf(int)$c$c>:
ed.setText(String.valueOf(x));
或使用Integer.toString(int)$c$c>:
ed.setText(Integer.toString(x));