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

3
  • Is it a string of numbers or is it the value of the resource ID? Commented Jun 3, 2014 at 17:57
  • possible duplicate of Unicode characters not displayed in TextView.setText Commented Jun 3, 2014 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 :( Commented Jun 3, 2014 at 18:02

2 Answers 2

1

You need to call first getResources() like this:

emailLabel.setText(getResources().getString(R.string.EMAIL_LABEL));
Sign up to request clarification or add additional context in comments.

2 Comments

This answer is wrong, setText accepts resource ids too. developer.android.com/reference/android/widget/…
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
1

Try this one

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

emailLabel.setText(res);

2 Comments

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
made a mistake of beginners today, be stronger tomorrow and never ever be shy from asking any questions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.