2012-08-03 39 views
6

嗨,大家好我是新來的,這是我的第一個問題硬編碼字符串「Test」,應使用@string資源

這裏是我的代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:orientation="horizontal" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 



<TextView 

    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/ref"  
/> 

<TextView 

    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Test" 
/> 

我不在第二次測試中不想使用字符串,我應該怎麼做?

回答

14

沒問題,您使用的是硬編碼的字符串。 如果您想了解更多信息,你可以看看:https://stackoverflow.com/a/8743887/1517996

的strings.xml

<resources> 
    <string name="Test">Test</string> 
<resources> 

,並使用它像

<TextView 

    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/Test" 
/> 
+0

我已經看到了這個鏈接,但我不想在我的代碼上出現任何錯誤:/有什麼辦法可以避免這個錯誤? – Edli 2012-08-03 13:14:33

+0

這不是一個錯誤,這是一個警告。如果你不想要這個警告,你應該在strings.xml中實現你的「測試」字符串作爲 Test並使用它像請看我編輯過的帖子 – 2012-08-03 13:20:47

+0

非常感謝!你真的幫我 – Edli 2012-08-03 13:51:10

0

您可以使用硬編碼值林佈局文件,它的罰款。如果你想刪除警告,你可以去Eclipse - >首選項 - > Android - > Lint錯誤檢查並尋找「硬編碼文本」。將其設置爲忽略,然後應用。

相關問題