`
lyunabc
  • 浏览: 526078 次
  • 性别: Icon_minigender_2
社区版块
存档分类
最新评论

Android ApiDemos示例解析(175):Views->Lists->8. Photos

 
阅读更多

本例也使用了自定义ListActivity的Layout,参见上例,同时也使用了自定义的ListAdapter (PhotoAdapter) ,其getView 返回一个ImageView ,参见Android ApiDemos示例解析(119):Views->Gallery->1. Photos

注意本例R.layout.list_8.xml 中将ListView 和一个TextView,其中TextView 的id为 @+id/emtpy,放在FrameLayout中,当ListView 为空时,TextView会显示出来,显示一行文字“no photos” 表示Listview 为空:

<!– The frame layout is here since we will be showing either
the empty view or the list view.  –>
<FrameLayout
android:layout_width=”match_parent”
android:layout_height=”0dip”
android:layout_weight=”1″ >
<!– Here is the list. Since we are using a ListActivity, we
have to call it “@android:id/list” so ListActivity will
find it –>
<ListView android:id=”@android:id/list”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:drawSelectorOnTop=”false”/>

<!– Here is the view to show if the list is emtpy –>
<TextView android:id=”@+id/empty”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:text=”@string/list_8_no_photos”/>

</FrameLayout>

其实ListActivity提供了一个更简洁的方法为ListView设置为空时显示的View,可以在Layout使用任意一种View,只要将其id 设置为”android:id/empty”,则可以用来显示ListView为空时的UI。

本例可以动态为ListView 随机添加照片,Clear 可以清空表,注意改变ListView数据源后,要调用notifyDataSetChanged()通知UI更新屏幕.


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics