私のプロジェクトでは、常に一定の ID をビューに設定する必要がありました。異なるアプリ ビルド間で一定の ID を意味します。いくつかの調査の結果、使用することで実現できvalues/public.xml
、そのファイルで宣言された id は将来のビルドで変更されないことがわかりました。問題は、一部のレイアウト ファイルでビューの ID を定義できないことです。これは、public.xml に追加する必要がある Id を持つ ImageView を含む私の layout.xml です。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/menu_item_selector" >
<ImageView
android:id="@+id/index_row_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="@dimen/padding_small" />
<ImageView
android:id="@+id/index_row_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/index_row_search" />
<TextView
android:id="@+id/index_row_caption"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/index_row_icon"
android:layout_toRightOf="@id/index_row_search"
android:gravity="right"
android:textAppearance="?android:attr/textAppearanceLarge" />
これは public.xml ファイルです。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<public type="string" name="no_internet" id="0xAA0a0001" />
<public type="id" name="index_row_search" id="0xAA0b0015" />
</resources>
Eclipse は、「index_row_search」の ID を追加した行にエラーを表示し、次のように言います。
error: Public symbol id/index_row_search declared here is not defined!
しかし、上記のレイアウト ファイルでわかるように、その ID を持つ ImageView があります。1 行上の文字列 ID 定義にエラーがないのは不思議です!
では、public.xml でビューの Id をどのように定義すればよいでしょうか?