开发者

How to display a message when the list view is empty in android

I am a new to Android stuff. I am creating an application that contains a lis开发者_StackOverflow中文版t 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 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.

If you don't want to use ListActivity you can always look at the implementation of ListView.java and adapt that.


There really isn't a way to do it without creating extra views.

If your List view item is just a TextView you can always add an item to your adapter that says "the list is empty" and just make sure you clear the adapter before you add the real results.

Or you can add a TextView as the HeaderView that also says "the list is empty" and make sure to hide the header when you add the real results. I think the first option might be the best best.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜