Android setText / R.string / values

S Arumik picture S Arumik · Jul 18, 2012 · Viewed 43.5k times · Source

I am having trouble with setting text in a text view with format and multiple values.

holder.car.setText(R.string.mycar + lm.getCarName() + R.string.year + lm.getYear());

this is giving me " 2143545 Camero 2143213 1977 "

I have tried few other "solutions" from the web

holder.car.setText(getString(R.string.mycar) + lm.getCarName() + getString(R.string.year) + lm.getYear());  << not work, getString undefine>>

I even tried String.valueOf(R.string.mycar); getResources().getText(R.String.mycar), still it didn't work.

It would be great if someone can help me, thanks

Answer

user1417127 picture user1417127 · Jul 18, 2012

Try this

holder.car.setText(getResources().getString(R.string.mycar));