Xamarin.android under Pull Refresh

Source: Internet
Author: User

First, preface

Today any app as long as there is a list, basically will use the drop-down refresh, and as a group of Xamarin we naturally will not lag behind, the following author will lead you in Xamarin to achieve the effect of the dropdown in Android.

Ii. preparatory work

Our pull-down refresh is not all done by hand, but using a third-party library, you can choose any way to download:

1.Github Download (source code)

2. Baidu Network Disk (source + the author's demo)

PS: If the reader chooses to download the referenced file from GitHub, the v4 of the source code is deleted and the new V4 is re-referenced.

Third, the text

The dropdown refresh and different from the official dropdown refresh demo, the official use of Actionbar rendering refresh status, but our normal usage of the app is through the pull-out drop-down refresh, and the third party drop-down refresh requires us to modify the layout of the Axml file to normal use, For example, we need the ListView support drop-down refresh to modify the Axml file as follows:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 android:orientation= "vertical"4 Android:layout_width= "Fill_parent"5 Android:layout_height= "Fill_parent">6     <PullToRefresharp.Android.Views.ViewWrapper7         Android:layout_width= "Fill_parent"8 Android:layout_height= "Fill_parent">9         <PullToRefresharp.Android.Widget.ListViewTen             Android:layout_width= "Match_parent" One Android:layout_height= "Wrap_content" A Android:id= "@+id/listview1" /> -     </PullToRefresharp.Android.Views.ViewWrapper> - </LinearLayout>

Where viewwrapper is necessary, and its child control ListView is not the one that the system comes with, we have to use our own, and of course the reader does not have to worry about how it differs from the ListView that comes with the system. In essence, third parties are inherited from the ListView, of course, third-party support is relatively limited, now only support ListView,GridView,Expandablelistview and ScrollView.

We then went back to MainActivity.cs, wrote the following code, listened to the refreshactivated event of the ListView, and simulated the load delay and then called the ListView The onrefreshcompleted method completes the load:

1         protected Override voidOnCreate (Bundle bundle)2         {3             Base. OnCreate (bundle);4 Setcontentview (Resource.Layout.Main);5 6LV = findviewbyid<pulltorefresharp.android.widget.listview>(Resource.Id.listview1);7Lv. Adapter =NewArrayadapter ( This, Android.Resource.Layout.SimpleListItem1, ITEMS);8Lv. refreshactivated + = (e,s) =9             {TenTask.Factory.StartNew (() = One                 { AThread.Sleep ( +); -Runonuithread (() = -                     { the LV. Onrefreshcompleted (); -                     }); -                 }); -             }; +}

The contents of the items are as follows:

1         Private Static string[] ITEMS =New string[] {"Abbaye de Belloc","Abbaye du Mont des Cats","Abertam","abondance","Ackawi","Acorn","Adelost","affidelice au Chablis","Afuega ' L Pitu","Airag","Airedale","Aisy Cendre","Allgauer Emmentaler","Abbaye de Belloc","Abbaye du Mont des Cats","Abertam","abondance","Ackawi","Acorn","Adelost","affidelice au Chablis","Afuega ' L Pitu","Airag","Airedale","Aisy Cendre","Allgauer Emmentaler"};

Then a simple pull-down refresh is done, so let's take a look at our results:

If the reader needs to customize this section only need to add a linearlayout control between the Viewwrapper and the ListView, which can be written with custom content, of course, the various animation effects naturally have to be implemented by themselves, I do not introduce the details here, as a welfare, Let's take a look at the drop-down officially implemented by the Actionbar (GitHub portal):

Xamarin.android under Pull Refresh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.