在Android的XML文件名和名称标签:身份证,机器人:机器人的区别 [英] Difference between android:id, android:name and name tags in Android XML files

查看:169
本文介绍了在Android的XML文件名和名称标签:身份证,机器人:机器人的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以澄清机器人之间的区别:ID 安卓名称标签Android的XML文件。他们似乎都的方式来引用的东西。

Can someone clarify the difference between android:id, android:name and name tags in Android's XML files. They all seem to be ways to reference things.

例如,当我有一个字符串数组中的 RES /价值/ array.xml 文件访问I使用名称字段定义数组中还没有的<一个href="http://developer.android.com/reference/android/content/res/Resources.html#getStringArray%28int%29"相对=nofollow>的Javadoc 称此为ID。

For example, when I have a string array in the res/values/array.xml file I access using the name field in the defined array yet the Javadoc refers to this as the "ID".

机器人:ID 似乎只是用在查看取值

我缺少的东西或岂不是更简单的有一个标签?

Am I missing something or would it not be simpler to have one tag?

推荐答案

没有,我不相信你错过了什么。虽然这些字段名称不同,这是我的理解是,他们都用于识别/参考资料。这具体意味着GUI元素(视图)在的情况下,Android的:在名称的情况下ID 和静态资源。

No, I don't believe you're missing anything. Although these fields are named differently, it's my understanding that they are both used to identify/reference resources. This specifically means GUI elements (views) in the case of android:id and static resources in the case of name.

要进入更深入,相信机器人:ID 属性只能分配给视图和类,扩展视图。这样做是为了使视图可以通过编程方式从code。使用访问 findViewById

To go into more depth, I believe the android:id attribute is assigned only to Views and classes that extend View. This is done so that the view can be programmatically accessed from your code using findViewById:

按钮myButton的=(按钮)findViewById(R.id.whatever_id_assigned_to_view)

这是这是由名称,简单地认定等资源的strings.xml或array.xml不同,如什么可能在字符串中找到了下面的例子。 XML:

This is different from resources such as strings.xml or array.xml which are identified simply by name, such as a following example of what might be found in strings.xml:

&LT;字符串名称=string_name&gt;文字资源此处&lt; /串&GT;

和访问使用的...

getResources()。的getText(R.string.string_name)

我想这些都是分开的组织原因。通过这种方式,产生的Andr​​oid资源文件(R.java)包含了意见R.id,包含在R.string字符串ID,阵列的ID在R.array指定的ID等。

I imagine these are separated for organizational reasons. This way the generated Android resource file (R.java) contains the IDs specified for views in R.id, the string IDs contained in R.string, array IDs in R.array etc.

这篇关于在Android的XML文件名和名称标签:身份证,机器人:机器人的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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