Alex Rivera | Logout

android - how to convert int to string and place it in a EditText?

Asked 2011-07-12T03:36:06.757
29

I have this piece of 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?

I've tried x.toString(), but it can't be compiled.

Edit
Report

1 Answer

88

Use +, the string concatenation operator:

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

or use String.valueOf(int):

ed.setText(String.valueOf(x));

or use Integer.toString(int):

ed.setText(Integer.toString(x));
answered 2011-07-12T03:37:55.407

Your Answer