2

I am working on a project with a spinner and ArrayList and I want to use left to right language (Persian) this is my code:

spinner1 = (Spinner) findViewById(R.id.spinnerVolume1);
List<String> list1 = new ArrayList<String>();
list1.add("*****");

I want to use Persian words as ***** but eclipse doesnt let me. I tried using String in res/values like this: res/values/strings.xml ==>> سلام and tried this one:

list1.add(R.String.hello);

but in code, Eclipse tells me to turn hello to String.

Also tried this code:

spinner1 = (Spinner) findViewById(R.id.spinnerVolume1);
List<Integer> list1 = new ArrayList<Integer>();
list1.add(R.String.hello);

but when I ran the app, I saw number (2131099648) instead of سلام

1
  • Do it like this list1.add(mContext.getResources().getString(R.String.hello)); Commented May 3, 2015 at 8:16

1 Answer 1

1

You should use getString():

spinner1 = (Spinner) findViewById(R.id.spinnerVolume1);
List<Integer> list1 = new ArrayList<Integer>();
list1.add(getString(R.String.hello));

public final String getString (int resId)
Return a localized string from the application's package's default string table.

Reference: http://developer.android.com/reference/android/content/Context.html#getString(int)

Sign up to request clarification or add additional context in comments.

2 Comments

worked well, one more question plz. what if I had <string-array name="hello">سلام</string-array> in res/value/strings
You should use getResources().getStringArray(R.array.hello). You can find more information here

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.