2012-09-28 100 views
-1

我目前正在對我的android應用程序進行國際化。這是我嘗試從string.xml從strings.xml文件獲取字符串

tv.setText(context.getResources().getString(R.string.)); 

得到串的方式,但Eclipse不建議我的任何預先定義的字符串,只是標準Android Strings的。我的文件夾結構如下圖所示:

res/values/strings.xml 

res/values-NO/strings.xml 

我可以看到,在這些對文件中的字符串已在R.java文件中的某些內存地址,像這樣的,例如:

public static final int enterPassword=0x7f06003c; 

我試圖Clean該項目,但它的奇怪,日食沒有建議任何東西,字符串存在於R.java

問題在哪裏?

回答

6

你應該導入你的R類。

import xxx.xxx.R;

import android.R;

+0

謝謝!將盡快接受 –

4

你的XML是這樣的:

 <?xml version="1.0" encoding="utf-8"?> 
    <resources> 
     <string name="yellow">Yellow</string> 
    </resources> 

和Java代碼:

tv.setText(getResources().getString(R.string.yellow)); 

和進口android.R儘管出現錯誤比嘗試運行該程序的時間還要多,但它會關閉

+0

這是正確的,我試圖讓在'enterPassword' –

+0

嘗試文本運行程序並清潔項目 - >構建項目比它會顯示 –

0

試試這個

Resources resources = getResources(); 

     String string = resources.getString(R.string.text); 

       TextView tv= (TextView)findViewById(R.id.text); 
       tv.settext(string); 
0

使用此:

String tab_label = getResources().getString(R.string.)); 

並確保你不是進口android.R

1

進口R與您的Package Path而不是android。

import com.example.R

,而不是import android.R;