In my project, I needed to set always-constant IDs to Views. I mean IDs that are constant between different app builds. After some investigation I found that it can be achieved by using values/public.xml
and any id declared in that file would not change on future builds. Now the problem is that I can't define an id of a view in some layout file.
This is my layout.xml containing an ImageView with an Id which should be added to public.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" />
and this is public.xml file:
<?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 shows an error on the line where I have added id of "index_row_search" and says:
error: Public symbol id/index_row_search declared here is not defined!
but as you can see in above layout file, I have an ImageView with that id. It's wondering that the string id definition one line above has no error!
So, how should I define Id of a View in public.xml?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…