Chr*_*ris 4 user-interface android listview
Android空列表布局
无论我做什么,我都无法显示空标签.在我的标签内,我有:
<LinearLayout
android:id="@+id/thisParticularTab"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/LastUpdated"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="List last updated: N/A" />
<ListView
android:id="@+id/mySpecialListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Click to fill the list" /></LinearLayout>
Run Code Online (Sandbox Code Playgroud)
但是,尽管我的ListView为空(没有显示任何项目,并且正在读取的数据库表为空),但不显示该按钮.有任何想法吗?
此外,当它出现时,我能否参考R.id.empty?这是否真的意味着每个活动只能有1个ListView /空?我的理解是'id'用于定义UI定义; 如何为其命名并将其指定为XML中的空视图?(我不想使用setEmptyView())
你在这里错过的是,按钮id也需要android前缀:
<Button
android:id="@android:id/empty"
... />
Run Code Online (Sandbox Code Playgroud)
@android:id/empty
指的android.R.id.empty
不是R.id.empty
.
确实,每个视图应该只有一个给定id的元素.如果您要创建自己的列表视图项,您自然会反复使用相同的元素(以及随后相同的ID),但在这些情况下,您可以通过以下方式访问它们:myListItem.findViewById(id)
与您的场景更相关的是,如果您发现需要添加另一个列表视图(需要另一个空标记),并且仍然希望listview本身处理隐藏和显示该项目,您可以使用该功能 setEmptyView(id)