最近幾天在研究上拉加載啊,下拉刷新啊什么的。然而坑爹的事情總是那么多。在xamarin.forms中,list自帶的,并沒有上拉加載的這個屬性(難道當(dāng)初他們封裝方法時,就不會想到數(shù)據(jù)多了會咋整嗎?)抱怨歸抱怨,問題總是要解決的。
創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供建始網(wǎng)站建設(shè)、建始做網(wǎng)站、建始網(wǎng)站設(shè)計(jì)、建始網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、建始企業(yè)網(wǎng)站模板建站服務(wù),10年建始做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
既然沒有,那就自己寫一個嘍~
我的思路是這樣的,
什么是上拉刷新,那是不是就是說,在當(dāng)前頁面,看到最后一個item的時候,我需要加載一些新的數(shù)據(jù),那我是不是可以寫一個,只要出現(xiàn)了最后一個item我們就去刷新最新數(shù)據(jù)呢?
1 public class InfiniteListView : ListView 2 { 3 public static readonly BindableProperty LoadMoreCommandProperty = BindableProperty.Create(nameof(LoadMoreCommand), typeof(ICommand), typeof(InfiniteListView)); 4 public static readonly BindableProperty CanLoadMoreProperty = BindableProperty.Create(nameof(CanLoadMore), typeof(bool), typeof(InfiniteListView), true); 5 6 public ICommand LoadMoreCommand 7 { 8 get { return (ICommand)GetValue(LoadMoreCommandProperty); } 9 set { SetValue(LoadMoreCommandProperty, value); }10 }11 12 public bool CanLoadMore13 {14 get15 {16 return (bool)GetValue(CanLoadMoreProperty);17 }18 set19 {20 SetValue(CanLoadMoreProperty, value);21 }22 }23 24 public InfiniteListView()25 {26 ItemAppearing += InfiniteListView_ItemAppearing;27 }28 29 private void InfiniteListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)30 {31 if (!CanLoadMore)32 {33 return;34 }35 var items = ItemsSource as IList;36 37 if (items != null && e.Item == items[items.Count - 1])38 {39 if (LoadMoreCommand != null && LoadMoreCommand.CanExecute(null))40 LoadMoreCommand.Execute(null);41 }42 }43 }
我們來繼承l(wèi)istview,來實(shí)現(xiàn)它的ItemAppearing方法,然后再方法里一次次的判斷有沒有到最后一個item(說實(shí)話我不知道這對程序好不好,現(xiàn)在只是想到了實(shí)現(xiàn)),只要出現(xiàn)了最后一個item,就去執(zhí)行綁定方法。
在頁面綁定中,需要
<ContentPage xmlns:common="clr-namespace:XXX.Common;assembly=XXX" > <common:InfiniteListView CanLoadMore="{Binding IsLoadMore}" LoadMoreCommand="{Binding LoadMoreLogCommand}"> </common:InfiniteListView>
So。。其實(shí)是不是很簡單?
簡單測試了一下,發(fā)現(xiàn)了一個問題。就是我的list數(shù)據(jù),有分組,一個list里面可能會有多個list,那最后一個item豈不是永遠(yuǎn)都是最外層的數(shù)據(jù)了?我把方法簡單的改了一下
文章名稱:Spark機(jī)器學(xué)習(xí)環(huán)境搭建
轉(zhuǎn)載來源:http://www.ekvhdxd.cn/article22/jiogjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、品牌網(wǎng)站設(shè)計(jì)、靜態(tài)網(wǎng)站、網(wǎng)站制作、自適應(yīng)網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)