How to use Android Pulltorefresh

Source: Internet
Author: User
<span id="Label3"></p><span id="OSC_h3_1"><span id="OSC_h3_1"></span></span>Android Studio Import Pulltorefresh<pre><pre><code>// 下载https://github.com/chrisbanes/Android-PullToRefresh// 解压,得到 extras,sample,library(主要)Android-PullToRefresh-master -> library// 在你项目的根目录创建一个lib目录[PATH][app] [src] [res] [build] build.gradle ...[build][gradle][lib] // 将 library 重名名为 pull [pull] [src] [res] [build] ... build.gradlesettings.gradle...// 修改 settings.gradle include ‘:app‘, ‘:lib:pull‘// 修改 [app]/build.gradledependencies { // Library compile project(‘:lib:pull‘)}// 创建 [lib]/[pull]/build.gradleapply plugin: ‘android-library‘android { compileSdkVersion 17 buildToolsVersion "21.1.2" sourceSets { main { manifest.srcFile ‘AndroidManifest.xml‘ java.srcDirs = [‘src‘] resources.srcDirs = [‘src‘] aidl.srcDirs = [‘aidl‘] renderscript.srcDirs = [‘src‘] res.srcDirs = [‘res‘] assets.srcDirs = [‘assets‘] } }}// 完成 </code></pre></pre> <span id="OSC_h3_2"><span id="OSC_h3_2"></span></span>Refreshing a ListView using Pulltorefresh <pre><code>In Activity_main.xml add a pulltorefreshlistview<relativelayout xmlns:android= "http://schemas.android.com/apk/ Res/android "android:layout_width=" match_parent "android:layout_height=" match_parent "> <com.handmark.pullt Orefresh.library.PullToRefreshListView android:id= "@+id/left_drawer" android:layout_width= "240dp" android:layout_ height= "match_parent" android:layout_gravity= "start" android:choicemode= "singlechoice" android:dividerheight= "1px "android:divider=" #ff000000 "android:background=" #ffffffff "android:layout_alignparenttop=" true "android:layo ut_alignparentend= "true" android:layout_alignparentstart= "true"/></relativelayout>//in Mainactivitypublic class Mainactivity extends Activity {pulltorefreshlistview lv; Private string[] Mlisttitle = {"name", "gender", "age", "place of residence", "mailbox"}; Private string[] mliststr = {"rain Pine momo", "male", "25", "beijing", "[email protected]"}; ListView Mlistview = null; Arraylist<map< String, object>> mdata = new arraylist<map<string, object>> (); @Override protected void onCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); Get pulltorefreshlistview View LV = (pulltorefreshlistview) Findviewbyid (r.id.left_drawer); .... int lengh = mlisttitle.length; for (int i = 0; i < lengh; i++) {map<string, object> item = new hashmap<string, object> (); Item.put ("title", mlisttitle[i]); Item.put ("text", mliststr[i]); Mdata.add (item); } // ... Simpleadapter adapter = new Simpleadapter (this, mdata, android. r.layout.simple_list_item_2, new string[]{"title", "text"}, new Int[]{android. r.id.text1, Android. r.id.text2}); Set the Simpleadapter to Pulltorefreshlistview lv.setadapter (adapter); Refresh Event Listener Lv.setonrefreshlistener (new pulltorefreshbase.onrefreshlistener<listview> () {@Override p Ublic void Onrefresh (pulltorefreshbase<listview> refreshview) {//... new asynctask<void, void, Voi d> () {@Override protected void Doinbackground (void ... params) {//handle Refresh task Try {thread.sleep (3000); } catch (interruptedexception E) {e.printstacktrace (); } return null; } @Override protected void OnPostExecute (void Reslst) {//more lines of content, notify Pulltorefre SH Flush End Lv.onrefreshcomplete (); }}.execute (); } }); }}</code></pre><p><p> How to use Android Pulltorefresh </p> </p></span>

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.