如何将 R.java 中的 int 值转换为 String
how to make int values in R.java into String
我正在使用微调器和 ArrayList
进行项目,我想使用从左到右的语言(波斯语)
这是我的代码:
spinner1 = (Spinner) findViewById(R.id.spinnerVolume1);
List<String> list1 = new ArrayList<String>();
list1.add("*****");
我想将波斯语单词用作 ***** 但 eclipse 不允许。
我尝试像这样在 res/values 中使用 String:
res/values/strings.xml ==>>
并尝试了这个:
list1.add(R.String.hello);
但在代码中,Eclipse 告诉我将 hello 转为 String。
也试过这个代码:
spinner1 = (Spinner) findViewById(R.id.spinnerVolume1);
List<Integer> list1 = new ArrayList<Integer>();
list1.add(R.String.hello);
但是当我 运行 应用程序时,我看到的是数字 (2131099648) 而不是 سلام
你应该使用 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.
参考:
http://developer.android.com/reference/android/content/Context.html#getString(int)
我正在使用微调器和 ArrayList
进行项目,我想使用从左到右的语言(波斯语)
这是我的代码:
spinner1 = (Spinner) findViewById(R.id.spinnerVolume1);
List<String> list1 = new ArrayList<String>();
list1.add("*****");
我想将波斯语单词用作 ***** 但 eclipse 不允许。 我尝试像这样在 res/values 中使用 String: res/values/strings.xml ==>> 并尝试了这个:
list1.add(R.String.hello);
但在代码中,Eclipse 告诉我将 hello 转为 String。
也试过这个代码:
spinner1 = (Spinner) findViewById(R.id.spinnerVolume1);
List<Integer> list1 = new ArrayList<Integer>();
list1.add(R.String.hello);
但是当我 运行 应用程序时,我看到的是数字 (2131099648) 而不是 سلام
你应该使用 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.
参考: http://developer.android.com/reference/android/content/Context.html#getString(int)