sách gpt4 ăn đã đi

android - 如何将 id 添加到 public.xml?

In lại 作者:太空狗 更新时间:2023-10-29 15:55:23 26 4
mua khóa gpt4 giày nike

在我的项目中,我需要为 View 设置始终不变的 ID。我的意思是在不同的应用程序构建之间保持不变的 ID。经过一番调查后,我发现它可以通过使用 values/public.xml 来实现,并且该文件中声明的任何 id 在未来的构建中都不会改变。现在的问题是我无法在某些布局文件中定义 View 的 id。这是我的 layout.xml,其中包含一个带有 Id 的 ImageView,应该将其添加到 public.xml:



android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/menu_item_selector" >

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

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

<>
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 文件:






eclipse 在我添加了“index_row_search”的 id 的行上显示错误并说:

错误:未定义此处声明的公共(public)符号 id/index_row_search!

但是正如您在上面的布局文件中看到的,我有一个具有该 ID 的 ImageView。奇怪上面一行的字符串id定义没有错误!

那么,在public.xml中应该如何定义一个View的Id呢?

câu trả lời hay nhất

在 values 中创建一个新的 xml ids.xml,所有 id 值都是常量。




我认为最好从 R.java 将资源 ID 复制到 public.xml,这是第一次避免像entry index is large than available symbols这样的错误,同时保留 type of resource保持一致。

关于android - 如何将 id 添加到 public.xml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12334857/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress