The third-party drop-down refresh control used this time is: Android-pull-refresh,: Https://github.com/chrisbanes/Android-PullToRefresh
This control applies to:
- Expandablelistview
- Listfragment
after downloading the extract from GitHub, after importing the Library,pulltorefreshlistfragment,pulltorefreshviewpager project, right-click on your new project, select Properties, After entering the page, click Add:
once added, you can start writing your demo with the following code:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:orientation=" vertical "&G T <!--the Pulltorefreshlistview replaces a standard ListView widget. --<com.handmark.pulltorefresh.library.pulltorefreshlistview xmlns:ptr= "Http://schemas.android.com/apk/re S-auto "android:id=" @+id/pull_refresh_list "android:layout_width=" Fill_parent "android:layout_height= "Fill_parent" android:cachecolorhint= "#00000000" android:divider= "#19000000" android:dividerheight= "4 DP "android:fadingedge=" None "Android:fastscrollenabled=" false "android:footerdividersenabled=" false " Android:headerdividersenabled= "false" android:smoothscrollbar= "true" ptr:ptrdrawable= "@drawable/ic_l Auncher "ptr:ptrmode=" both "/></linearlayout>
Import Java.util.arraylist;import java.util.list;import Android.app.activity;import Android.os.asynctask;import Android.os.bundle;import Android.widget.arrayadapter;import Android.widget.listview;import android.widget.Toast; Import Com.handmark.pulltorefresh.library.pulltorefreshbase;import Com.handmark.pulltorefresh.library.pulltorefreshbase.onlastitemvisiblelistener;import Com.handmark.pulltorefresh.library.pulltorefreshbase.onrefreshlistener;import com.handmark.pulltorefresh.library.pulltorefreshlistview;/** * Mainactivity---implemented with a third-party pull-down refresh control * @author seabear * */ public class Mainactivity extends Activity {private Pulltorefreshlistview mpulltorefreshlistview;private list< string> marraylist = new arraylist<string> ();p rivate arrayadapter<string> mArrayAdapter;private int mnums = 0; @Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); Mpulltorefreshlistview = (Pulltorefreshlistview) This.findVIewbyid (r.id.pull_refresh_list); marrayadapter = new Arrayadapter<> (this, Android. R.layout.simple_list_item_1, marraylist); Mpulltorefreshlistview.setadapter (Marrayadapter); Mpulltorefreshlistview.setonrefreshlistener (New onrefreshlistener<listview> () {@Overridepublic void Onrefresh (pulltorefreshbase<listview> Refreshview) {//TODO auto-generated method Stubnew Getdatatask (). Execute ();}});} Private class Getdatatask extends Asynctask<void, void, string>{@Overrideprotected String doinbackground (void ... params) {//simulates a background job.mnums++;try {thread.sleep ()} catch (Interruptedexception e) {}return "+" + Str Ing.valueof (mnums) + "line";} @Overrideprotected void OnPostExecute (String result) {Marraylist.add (result); Marrayadapter.notifydatasetchanged () ;//Call Onrefreshcomplete If the list has been refreshed.mPullToRefreshListView.onRefreshComplete (); Super.onpostexecute (result);}}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android dropdown Refresh control using the third-party open source control implementation