ListView的小知識

2022-08-21 00:12:13 字數 871 閱讀 4410

1.設定專案分割功能

android:divider="@android:color/blue"

android:dividerheight="10dp"

2.隱藏滾動條

android:scrollbars = "none"

3.指定具體顯示的item

listview.setselection(n);//n代表第n個item

4.動態修改listview

mdata.add("new");//

將資料放入list中

madaoter.notifydatasetchanged();//

重新整理listview

注:傳進adapter的資料list是同乙個list(指標不能變),否則無法實現效果

5.處理空的listview

listview提供了setemptyview()的方法,我們可以給listview設定乙個在空資料下顯示的預設提示。

listview listview =(listview) findviewbyid(r.id.listview);

listview.setemptyview(findviewbyid(r.id.emptyview));

6.listview的滑動監聽

ontouchlistener是view中的監聽事件。通過監聽action_down、action_move、action_up。普通的監聽

作用:判斷使用者的滑動方向。

onscrolllistener是abslistview的監聽事件,封裝很多關於listview的相關資訊。(android群英傳  p73頁)

WPF中ListView小Demo的資料繫結應用

wpf中的資料繫結非常的好用,下面的例子可以說明這點.效果圖 我們在xaml 中建立乙個listview 我們設定listview中的樣式繫結為靜態繫結 分別定義三個列用來繫結資料id,name,balance 如下 name listview itemcontainerstyle itemssou...

ListView巢狀ListView的思路

1.在activity中,布局中新增原生listview作為 父listview 2.在父listview中新增自定義的 子listview 3.子listview中的布局為單個item的布局。4.書寫父listview的adapter public class eventcitylistadapt...

Listview巢狀Listview的實現方法

第一種方法 重寫listview的onmeasure方法 public class childlistview extends listview public childlistview context context,attributeset attrs,int defstyle public c...