我是一个新到Android的东西。我创建包含将获得动态填充列表视图的应用程序。我的要求是,当该列表是空的,我想显示的消息。我不想只是为了显示此消息创建其他的视图。有没有什么好的办法做到这一点?有什么建议?
I am a new to Android stuff. I am creating an application that contains a list view that will get dynamically populated. My requirement is when the list is empty, I would like to show a message. I don't want to create additional views just for displaying this message. Is there any nice way to do this? Any suggestions?
ListActivity
有一个功能,它显示了一个特定视图时,列表是空的: @android:ID /空
。您可以轻松地只使用一个自定义布局与 ListActivity
来实现这一目标。
ListActivity
has a feature where it shows a specific view when the list is empty: @android:id/empty
. You can easily just use a custom layout with ListActivity
to achieve this.
如果你不想使用 ListActivity
你总是可以看看ListView.java并适应这一点。
If you don't want to use ListActivity
you can always look at the implementation of ListView.java and adapt that.