2011-07-12 128 views
25

我有这样一段代码:android-如何将int转换为字符串并将其置于EditText中?

ed = (EditText) findViewById (R.id.box); 
int x = 10; 
ed.setText (x); 

它原来是一个错误。我知道我必须将其更改为字符串,但我该怎么做?我试过x.toString(),但它不能编译。

+1

在这种情况下,提出新问题回复:'char'。 (提示:答案是将'char'转换为'String'和'Integer.parseInt()'字符串。) –

+0

为什么你不从谷歌尝试它很容易得到这个答案? –

+0

请勿在帖子中一次询问多个问题。我已经编辑出第二个问题,请将其作为一个新问题。 – Kev

回答

8

尝试Integer.toString(integer value);方法

ed = (EditText)findViewById(R.id.box); 
int x = 10; 
ed.setText(Integer.toString(x)); 
1

尝试使用String.format()

ed = (EditText) findViewById (R.id.box); 
int x = 10; 
ed.setText(String.format("%s",x)); 
0

使用此代码中的:

String.valueOf(x);