@+id/android:list 和@+id/list 有什么区别
我想知道 @+id/android:list
和 @+id/list
之间有什么区别.我知道最后一个是常规 id 分配,但第一个看起来不同.它有何特别之处?
I am wondering what's the difference between @+id/android:list
and @+id/list
. I know the last one which is a regular id assignment but the first looks different. What makes it special?
我在哪里看到的:我正在研究 ListView、ListAdapter 和类似的东西,作者在布局 xml 文件中定义 ListView 如下:
Where I saw it: I was studying on ListView, ListAdapter and things like that and the author define the ListView in layout xml file as below :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView
android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/main_no_items"/>
</LinearLayout>
还要让我提一下 @+id/android:empty
id.
and also let me mention @+id/android:empty
id as well.
而且他还扩展了 ListActivity
类.
And he also extends ListActivity
class.
这是文章来源.
还有我心中的疑问:
- 我们应该扩展
ListActivity
吗?也许我想要一个还包含其他视图的活动. - 我们使用
@+id/android:list
只是因为我们扩展了ListActivity
或者如果我们扩展Activity
就可以使用相同的约定?
- Should we extend
ListActivity
? Maybe I want an Activity which also contains other Views. - We use
@+id/android:list
just because we extendListActivity
or we can use the same convention if we extendActivity
?
谢谢.
Android 中的资源 ID 是特定于一个包的(这很好,否则如果你的应用程序同时处理多个包,你就会有很多冲突同时).
Resource IDs in Android are specific to a package (which is good, or else you'd have lots of conflicts if your app is dealing with several packages at the same time).
@+id/list
将在您的应用程序(=您的包)中创建一个名为list"的资源 ID,并为其提供唯一 ID.在代码中,这将是 R.id.list
.
@+id/list
will create a resource ID in your app (=your package) with the name "list" and give it a unique ID. In code, that would be R.id.list
.
@android:id/list
将使用包 android 中的 IDlist"(在代码中,它是 android.R.id.list
.
@android:id/list
will use the ID "list" from the package android (which, in code, would be android.R.id.list
.
需要添加 David Hedlund 指出的更正:正确的参考是 @android:id/list
.此外,+
表示您正在定义一个新 ID - 当您引用在 Android API 中定义的某些内容时,您显然不需要它.
Need to add the corrections David Hedlund pointed out: The proper reference would be @android:id/list
. Also, +
indicates you're defining a new ID - you obviously don't need that when you're referencing something that was defined in the Android API.