0

In my Android application I have some arabic strings stored in the strings.xml file. when I use the string from the layout xml via:

android:text="@string/EMAIL_LABEL

It works fine, but when I call it from java code like:

emailLabel.setText(R.string.EMAIL_LABEL) 

it shows me only numbers instead

Anyone can advice please?

Thanks in Advance

Giru Bhai
  • 14,370
  • 5
  • 46
  • 74
Marwan Jaber
  • 611
  • 11
  • 27
  • Is it a string of numbers or is it the value of the resource ID? – Dan S Jun 03 '14 at 17:57
  • possible duplicate of [Unicode characters not displayed in TextView.setText](http://stackoverflow.com/questions/4522337/unicode-characters-not-displayed-in-textview-settext) – ranjk89 Jun 03 '14 at 17:57
  • Thank you, it was my bad! I used setText(R.string.TEXT_ID) so it printed the id of the string and not the string value itself, I had to do getString(ID), It's a mistake of a beginner but the fact that I'm not, embarrassing :( – Marwan Jaber Jun 03 '14 at 18:02

2 Answers2

1

You need to call first getResources() like this:

emailLabel.setText(getResources().getString(R.string.EMAIL_LABEL));
Gustavo Rozolin
  • 1,070
  • 2
  • 13
  • 21
  • This answer is wrong, setText accepts resource ids too. http://developer.android.com/reference/android/widget/TextView.html#setText(int) – MLProgrammer-CiM Jun 03 '14 at 18:00
  • 1
    The solution worked fine for me, Thank you, it was my bad! I used setText(R.string.TEXT_ID) so it printed the id of the string and not the string value itself, I had to do getString(ID), It's a mistake of a beginner but the fact that I'm not, embarrassing – Marwan Jaber Jun 03 '14 at 18:03
1

Try this one

String res = getResource ().getString( R.string.EMAIL_LABEL);

emailLabel.setText(res);
NoXSaeeD
  • 924
  • 1
  • 7
  • 13
  • Actually I made a mistake of beginners even I'm not, so it's embarrassing a bit, but thank you very much you saved my life :D – Marwan Jaber Jun 03 '14 at 18:10
  • 1
    made a mistake of beginners today, be stronger tomorrow and never ever be shy from asking any questions – NoXSaeeD Jun 03 '14 at 18:22