. Net Moving Android 4.4 daily notes (--pulltorefresh) drop-down refresh using

Source: Internet
Author: User

Drop-down refresh a lot of places are used, Sina Weibo,, Baidu News

Here we use an open source library called: Pulltorefresh

Open Source Address: Https://github.com/chenyoca/pull-to-refresh

: Https://github.com/chenyoca/pull-to-refresh/archive/master.zip

After extracting the code, import it into the project via Ecplise.

Library path Reference error may occur after import

Right-click on the project to correct the library

Running the main activity

Then you can see the effect! Next we create a project ourselves to use this control

Create a new project Usingpulltorefresh

To reference the library after creation, which is a bit like a C # project, to reference an assembly (3 libraries are referenced)

A different jar version error is reported after the reference is completed

So we're going to make the library and the version of our project consistent.

Copy the Android-support-v4.jar under the Libs

Copy to the newly referenced 3 libraries and replace the Android-support-v4.jar under Libs

Modify the code for Mianactivity.java and Activity_main.xml

Package Com.example.usingpulltorefresh;import Java.util.arraylist;import java.util.list;import Com.handmark.pulltorefresh.library.pulltorefreshbase;import Com.handmark.pulltorefresh.library.pulltorefreshbase.onrefreshlistener;import Com.handmark.pulltorefresh.library.pulltorefreshlistview;import Android.app.activity;import Android.app.actionbar;import Android.app.fragment;import Android.os.asynctask;import Android.os.Bundle;import Android.view.layoutinflater;import Android.view.menu;import Android.view.menuitem;import Android.view.View;import Android.view.viewgroup;import android.widget.arrayadapter;import android.widget.listview;import android.os.Build; Public classMainactivity extends Activity {PrivatePulltorefreshlistview LV; PrivateArrayadapter<string>adapter; PrivateList<string>list; @Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main); //Find to controlLV =(Pulltorefreshlistview) Findviewbyid (r.id.lv); List=NewArraylist<string>(); List.add ("Banana"); List.add ("Apple"); Adapter=NewArrayadapter<string> ( This, Android.        R.layout.simple_list_item_1,list);                Lv.setadapter (adapter); Lv.setonrefreshlistener (NewOnrefreshlistener<listview>() {@Override Public voidOnrefresh (pulltorefreshbase<listview>Refreshview) {                //TODO auto-generated Method Stub                NewAsynctask<void,void,void>() {@Overrideprotectedvoid Doinbackground (void ... arg0) {//TODO auto-generated Method Stub                        Try{Thread.Sleep ( -); } Catch(interruptedexception e) {//TODO auto-generated Catch blockE.printstacktrace (); }                        return NULL; }                                        protected voidOnPostExecute (Void result) {Adapter.addall ("Watermelon","Orange","Dragon Fruit");                    Lv.onrefreshcomplete ();            }}.execute ();    }        }); } @Override Publicboolean Oncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true; } @Override Publicboolean onoptionsitemselected (MenuItem item) {//Handle Action Bar item clicks here. The Action Bar would//automatically handle clicks on the Home/up button, so long//As you specify a the parent activity in Androidmanifest.xml.        intID =Item.getitemid (); if(id = =r.id.action_settings) {            return true; }        returnsuper.onoptionsitemselected (item); }    }
mainactivity
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:id= "@+id/container"android:orientation= "vertical"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context= "Com.example.usingpulltorefresh.MainActivity"Tools:ignore= "Mergerootframe" >    <Com.handmark.pulltorefresh.library.PullToRefreshListViewAndroid:id= "@+id/lv"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"        >    </Com.handmark.pulltorefresh.library.PullToRefreshListView></LinearLayout>
Activity_main

OK, you can run it!

Direct Download Source: Http://pan.baidu.com/s/1mgKBkrI

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.