How to set text to a text view from a string.xml and normal string at a time

Viewed 39656

R.string.Converasation contains Conversation Here is the code

tv.setText(R.string.Converasation+"HELLo");

textview view is taking int value of R.string.Converasation and string value of HELLo and finally displays 2131034187Hello but i want ConverasationHello

how to resolve this..

7 Answers

Try following code:

  Resources res = context.getResources();
  float floatConverasation = 1.1f;
  String strfloatConverasation = "HELLO";
  tv.setText(String.format(Locale.ENGLISH,"%s %f %s",
    res.getString(R.string.conversation), floatConverasation, strfloatConverasation));

It can be achieved by passing the string inside the resource i.e. getResources().getString(R.string.yourStringName)

Related