Advanced article-user interface: 6.android Studio using GitHub open Source library for pull-down refresh

Source: Internet
Author: User

To tell you the truth, this is the first time I've ever been so serious. With GitHub Open Source Library, I have been listening to the great God for this world-class open Source Library, and finally realized today. Because the drop-down Refresh class library was developed under Eclipse, how Eclipse uses it is very detailed if the tutorials are imported online. Yesterday I tried for a long time to find that because I am not very familiar with Android studio, so when referencing the class library when found impossible. But this morning, the only thing I want to do is to make sure that this pull-down refresh works. I went online to find the Android Studio Import Class Library tutorial, import Pulltorefresh Tutorial, but the web with the old version of the Android studio, the operation is very cumbersome, for I am groping for people who are difficult to understand, and, I am using the latest version of Android Studio, so those tutorials on the web are not particularly suitable for me. So there's no way to find out for yourself. Fortunately, it took about one hours to finally import the class library and successfully implemented the effect of the drop-down refresh. Although there are some small problems, for example, I do not understand why add Pulltorefresh in the XML space, the attributes of the width of the height id ah what do not have code hints, resulting in my own to hit the code when some guilty. Of course, this is harmless, and later on why there is no code hint.

The new version of Android studio imports the class library and uses it to implement a drop-down refresh. (I feel like other libraries should also be similar)

Android Studio version:

Tutorial Start:

(1) Download the source code of Pulltorefresh on GitHub website. SOURCE Project Address: Https://github.com/chrisbanes/Android-PullToRefresh

(2) Import the original project's class library in Android Studio

File->new->import module-> Select File, select Library folder, Extras inside the Pulltorefreshviewpager and pulltorefreshlistfragment.

After the import in your project will appear these three libraries, because the new version of as is very developer's consideration, so gradle do not have to change their own, it fully automatic synchronization!

(3) Right-click on the project->open module settings-> to the left to select the app (i.e. your own project), right select dependencies-> dot below the small plus, select module dependency- > Select all of the class libraries we have just imported.

(4) If there is no error, then the Pulltorefresh class library is fully available.

(5) Demo Source:

Mainactivity.java:

ImportAndroid.os.AsyncTask;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.ListView;Importcom.handmark.pulltorefresh.library.PullToRefreshBase;ImportCom.handmark.pulltorefresh.library.PullToRefreshListView;ImportJava.lang.reflect.Array;Importjava.util.ArrayList;Importjava.util.List; Public classMainactivityextendsappcompatactivity {PrivatePulltorefreshlistview Pl; PrivateArrayadapter<string>Adaper; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); PL=(Pulltorefreshlistview) Findviewbyid (R.ID.L); List<String> arr =NewArraylist<string>(); Arr.add ("Test1"); Arr.add ("Test2"); Arr.add ("Test3"); Arr.add ("Test4"); Arr.add ("Test5"); Adaper=NewArrayadapter<string> ( ThisAndroid. R.layout.simple_list_item_1,arr);//Initializing DataPl.setadapter (Adaper); Pl.setonrefreshlistener (NewPulltorefreshbase.onrefreshlistener2<listview>() {@Override Public voidOnpulldowntorefresh (pulltorefreshbase<listview>Refreshview) {                 NewAsynctask<void,void,void>() {@Overrideprotectedvoid Doinbackground (void ... voids) {//perform operations in the background, where the synchronization process is simulated with delay                         Try{Thread.Sleep (3000); } Catch(interruptedexception e) {e.printstacktrace (); }                         return NULL; } @Overrideprotected voidOnPostExecute (Void aVoid) {//interacting with the database, adding data                         Super. OnPostExecute (aVoid); Adaper.addall ("Hello", "success");   Pl.onrefreshcomplete (); //Notification synchronization Complete}}.execute (); } @Override Public voidOnpulluptorefresh (pulltorefreshbase<listview>Refreshview)    {            }        }); }}

Activity_main.xml:

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context= "Com.example.lzc.myapplication.MainActivity">    <Com.handmark.pulltorefresh.library.PullToRefreshListViewAndroid:id= "@+id/l"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent">    </Com.handmark.pulltorefresh.library.PullToRefreshListView></LinearLayout>

Advanced article-user interface: 6.android Studio using GitHub open Source library for pull-down refresh

Related Article

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.