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.
This question is related to
android
string
android-edittext
integer
type-conversion
try Integer.toString(integer value);
method as
ed = (EditText)findViewById(R.id.box);
int x = 10;
ed.setText(Integer.toString(x));
Try using String.format()
:
ed = (EditText) findViewById (R.id.box);
int x = 10;
ed.setText(String.format("%s",x));
Use this in your code:
String.valueOf(x);
Source: Stackoverflow.com