效果图:

在Android中,ListView用来显示一个列表的控件。当然,用户可以选择并操作这个列表,同时必然会触发一些事件。当鼠标滚动时会触发setOnItemSelectedListener事件,点击时则会产生setOnItemClickListener事件。
在编码实现时,我们先创LinearLayout对象和ListView对象,LinearLayout用来显示ListView;然后通过ListAdapter将数据与ListView链接起来;接着ListAdapter添加到ListView中;最后将ListView添加到LinearLayout中,让屏幕显示LinearLayout。要处理ListView事件,需要为ListView视图添加setOnItemSelectedListener监听以及setOnItemClickListener监听。
xml:
- "1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- >
-
- <ListView
- android:id="@