5

これが私のコードです:

<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"
     />
 
</LinearLayout>

2 番目のテストで文字列を使用したくありません。私は何をすべきか?

4

3 に答える 3

14

ハードコードされた文字列を使用しているかどうかに問題はありません。さらに詳しい情報が必要な場合は、https ://stackoverflow.com/a/8743887/1517996 をご覧ください。

文字列.xml

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

linレイアウトファイルのように使用します

<TextView

    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/Test"
 />
于 2012-08-03T11:56:01.043 に答える
0

ハードコードされた値を使用できますが、問題ありません。警告を削除したい場合は、Eclipse -> 設定 -> Android -> Lint Error Checking に移動して、"Hardcoded Text" を探します。無視して適用するように設定します。

于 2014-10-13T15:24:40.723 に答える