如何添加id来public.xml? [英] How to add id to public.xml?

查看:888
本文介绍了如何添加id来public.xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目,我需要设置始终恒定ID来查看。我的意思的ID是不变的不同的应用程序版本。经过一番调查,我发现,它可以通过使用可以实现值/ public.xml 并在将来的版本在该文件中声明的ID不会改变。现在的问题是,我不能确定在一些布局文件的视图的ID。 这是我的layout.xml含有ImageView的同一个Id它应该添加到public.xml:

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

这是public.xml文件:

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>

日食显示了在那里我已经加入index_row_search的ID,并表示该行的错误:

eclipse shows an error on the line where I have added id of "index_row_search" and says:

错误:公共符号ID / index_row_search这里声明没有定义

但你可以在上面的布局文件中看到,我有那个ID的ImageView的。它不知道该字符串ID定义一条线上面有没有错误!

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!

那么,我应该如何界定的public.xml一个视图id?

So, how should I define Id of a View in public.xml?

推荐答案

所有的ID值,这些值是恒定的创建中值一个新的XML ids.xml。

Create a new xml ids.xml in values with all the id values which are to be constant.

<resources>
  <item type="id" name="index_row_search" />
</resources>

我觉得它的更好,如果你复制的资源ID从R.java,在第一时间,以避免类似错误public.xml 项指数低于可用符号更大,并保持< A HREF =htt​​p://stackoverflow.com/a/6646113/1109425>资源的类型是一致的。

I think its better if you copy the resource ids to public.xml from the R.java, the first time to avoid errors like entry index is larger than available symbols and also to keep the type of resource to be consistent.

这篇关于如何添加id来public.xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆