【发布时间】:2015-08-28 23:16:27
【问题描述】:
用这个答案解决了How can I get a resource content from a static context?
今天我决定我的应用程序应该支持不同的语言,所以我更改了每个普通字符串,例如...:
String hw = "hello world";
..to:
XML:
<string name="hello_world">Hello world!</string>
App:
String hw= getResources().getString(R.string.hello_world);
但由于某种原因,它不再显示文本。当我使用正常的方法时,一切都很好,但现在却不行。我也试过 getText() 但这也不起作用。我正在使用字符串将它们放入这样的 ArrayList 中:
public hello(){
meineListe.add(hello_world);
完整的课程:
public class favorites extends Activity {
static int x = -1;
private ArrayList<String> meineListe = new ArrayList<String>();
public favorites(){
String a1 = getResources().getString(R.string.a1);
String aa1 = getResources().getString(R.string.aa1);
String aaa1 = getResources().getString(R.string.aaa1);
【问题讨论】:
-
“我也尝试过 getText()” 尝试过如何使用?您是否使用日志或断点来查看
hw是什么? -
String hw = (String) getText(R.string.hello_world);