我不知道这是可能的,是有可能,我只用它的id夸大一个ListView?谢谢你。
I don't know if this is possible, is it possible for me to inflate a listview using only its id? Thanks.
我想你可能会感到困惑的组件ID和布局ID之间的差异。
I think you may be confused about the difference between a component ID and a layout ID.
一个布局ID是指一种布局的XML文件的名称。例如,如果你有一个名为布局 RES /布局/ home_activity.xml
,其ID将被存储为 R.layout.home_activity
。
A layout ID refers to the name of a layout XML file. For example, if you have a layout named res/layout/home_activity.xml
, its ID would be stored as R.layout.home_activity
.
一个组件ID指的是一个用户界面组件的现有布局内的身份。所以,你的 home_activity.xml
布局中,你可能有< TextView的机器人:ID =@ + ID / my_textview/>
。该视图的ID是 R.id.my_textview
。
A component ID refers to the identity of a UI component inside an existing layout. So, inside your home_activity.xml
layout you might have <TextView android:id="@+id/my_textview" />
. The ID of that View is R.id.my_textview
.
您只能使用充气布局ID布局。 充气的成分标识没有任何意义,除非你抬高布局作为具有特定ID的视图一个孩子。
You can only inflate layouts using a layout ID. 'Inflating' a component ID doesn't make any sense, unless you inflate a layout as a child of a View with a specific ID.