![](/img/trans.png)
[英]Is it possible to get the a (int -> String) mapping from R.java
[英]Cannot convert from int to String from R.java
我有一个Dashboard.java文件,在其中使用在R.java自动生成的文件中解析的strings.xml。
当我尝试做时:
public String BASE_URL = R.string.BASE_URL;
自然会告诉Cannot无法从int转换为String。
但这就是从string.xml中选择的翻译内容。
有没有解决的办法?
谢谢
用这个
String BASE_URL = getResources().getString(R.string.BASE_URL);
或者您可以从以下代码中复制:
getResources().getString(R.string.BASE_URL);
Resources res = getResources();
String url = res.getString(R.string.hello_world);
EditText et=(EditText)findViewById(R.id.editText1);
et.setText(url);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.