ImageVerifierCode 换一换
格式:DOCX , 页数:19 ,大小:143.47KB ,
资源ID:7161495      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/7161495.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(PullToRefresh使用详解实现异步加载的下拉刷新列表资料.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

PullToRefresh使用详解实现异步加载的下拉刷新列表资料.docx

1、PullToRefresh使用详解实现异步加载的下拉刷新列表资料PullToRefresh使用详解(二)-实现异步加载的下拉刷新列表 前言:根据前几篇的阶段性成果(下拉刷新、异步加载),将其集成,就成了这篇文章,这篇文章代码量比较大,对于异步加载的部分,除了更改了getView()里绑定部分的代码,其它的都没有动,所以异步刷新里的代码我就不往里贴了,只贴MainActivity.java的代码,主要看看主程序是如何实现异步加载图片和下拉刷新的。效果图:初始化后,正在加载图片 加载出一部分 下拉刷新 新生成的ITEM 加载完成新生成ITEM的图片一、MainActivity.java其它的代码就

2、不讲了,我只说说这个主页面是如何动作的,先看看整体代码。java view plaincopyprint?1. packagecom.example.try_simpleadapter_new;2. /*3. *完成与服务器通信的下拉刷新4. *authorharvic5. */6. importjava.io.BufferedReader;7. importjava.io.InputStreamReader;8. importjava.util.ArrayList;9. importjava.util.List;10. 11. importorg.apache.http.HttpEntity

3、;12. importorg.apache.http.HttpResponse;13. importorg.apache.http.NameValuePair;14. importorg.apache.http.client.entity.UrlEncodedFormEntity;15. importorg.apache.http.client.methods.HttpPost;16. importorg.apache.http.impl.client.DefaultHttpClient;17. importorg.apache.http.message.BasicNameValuePair;

4、18. importorg.apache.http.protocol.HTTP;19. importorg.json.JSONArray;20. 21. 22. importcom.handmark.pulltorefresh.library.PullToRefreshBase;23. importcom.handmark.pulltorefresh.library.PullToRefreshListView;24. importcom.handmark.pulltorefresh.library.PullToRefreshBase.Mode;25. importcom.handmark.pu

5、lltorefresh.library.PullToRefreshBase.OnRefreshListener;26. 27. importandroid.os.AsyncTask;28. importandroid.os.Bundle;29. importandroid.text.format.DateUtils;30. importandroid.util.Log;31. importandroid.widget.ListView;32. importandroid.app.ListActivity;33. 34. publicclassMainActivityextendsListAct

6、ivity35. 36. privateStringserverIP=http:/222.195.151.19;37. privateListmData;38. privatePullToRefreshListViewmPullRefreshListView;39. ImageAndTextListAdapteradapter=null;40. Override41. publicvoidonCreate(BundlesavedInstanceState)42. super.onCreate(savedInstanceState);43. setContentView(R.layout.act

7、ivity_main);44. 45. mPullRefreshListView=(PullToRefreshListView)findViewById(R.id.pull_refresh_list);46. 47. /设定下拉监听函数 48. mPullRefreshListView.setOnRefreshListener(newOnRefreshListener()49. Override50. publicvoidonRefresh(PullToRefreshBaserefreshView)51. Stringlabel=DateUtils.formatDateTime(getAppl

8、icationContext(),System.currentTimeMillis(),52. DateUtils.FORMAT_SHOW_TIME|DateUtils.FORMAT_SHOW_DATE|DateUtils.FORMAT_ABBREV_ALL);53. 54. /UpdatetheLastUpdatedLabel 55. refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);56. 57. Log.d(msg,this=+this);58. /Doworktorefreshthelisthere. 59.

9、newGetDataTask().execute();60. 61. 62. );63. 64. mPullRefreshListView.setMode(Mode.PULL_FROM_END);/设置底部下拉刷新模式 65. /传参生成适配器 66. mData=getData();67. ListViewactualListView=mPullRefreshListView.getRefreshableView();68. adapter=newImageAndTextListAdapter(this,mData,actualListView);69. 70. /设置适配器 71. act

10、ualListView.setAdapter(adapter);72. 73. 74. privateListgetData()75. /创建默认的httpClient实例. 76. DefaultHttpClienthttpclient=newDefaultHttpClient();77. HttpResponseresponse=null;78. HttpEntityentity=null;79. 80. StringBuilderbuilder=newStringBuilder();81. JSONArrayjsonArray=null;82. 83. Listlist=newArray

11、List();84. 85. try86. /创建httpost.访问本地服务器网址 87. HttpPosthttpost=newHttpPost(serverIP+/try_an_server/index.php);88. 89. /构造POST方法的name:value参数对 90. Listvps=newArrayList();91. /将参数传入post方法中 92. vps.add(newBasicNameValuePair(action,insert);93. vps.add(newBasicNameValuePair(name,进去了);94. 95. httpost.setE

12、ntity(newUrlEncodedFormEntity(vps,HTTP.UTF_8);96. response=httpclient.execute(httpost);/执行 97. 98. if(response.getEntity()!=null)99. /如果服务器端JSON没写对,这句是会出异常,是执行不过去的 100. BufferedReaderreader=newBufferedReader(newInputStreamReader(response.getEntity().getContent();101. Strings=reader.readLine();102. f

13、or(;s!=null;s=reader.readLine()103. builder.append(s);104. 105. Log.i(msg,builder.toString=+builder.toString();106. 107. jsonArray=newJSONArray(builder.toString();108. for(inti=0;ijsonArray.length();i+)109. if(jsonArray.getJSONObject(i).getInt(id)=1)110. Stringname=jsonArray.getJSONObject(i).getStri

14、ng(name);111. Stringinfo=jsonArray.getJSONObject(i).getString(info);112. StringPicName=jsonArray.getJSONObject(i).getString(photo);113. StringpicURL=serverIP+/try_an_server/+PicName+.jpg;114. 115. ImageAndTextitem=newImageAndText(picURL,name,info);116. list.add(item);117. 118. 119. 120. catch(Except

15、ione)121. e.printStackTrace();122. finally123. try124. if(entity!=null)125. 126. httpclient.getConnectionManager().shutdown();/关闭连接 127. /这两种释放连接的方法都可以 128. 129. catch(Exceptione)130. /TODOAuto-generatedcatchblock 131. e.printStackTrace();132. 133. 134. 135. returnlist;136. 137. 138. 139. 140. 141.

16、privateclassGetDataTaskextendsAsyncTask142. 143. /后台处理部分 144. Override145. protectedImageAndTextdoInBackground(Void.params)146. /Simulatesabackgroundjob. 147. ImageAndTextitem=null;148. try149. item=newImageAndText(serverIP+/try_an_server/xizang.jpg,sss,ssss);150. catch(Exceptione)151. /TODO:handlee

17、xception 152. setTitle(map出错了);153. 154. 155. returnitem;156. 157. 158. /这里是对刷新的响应,可以利用addFirst()和addLast()函数将新加的内容加到LISTView中 159. /根据AsyncTask的原理,onPostExecute里的result的值就是doInBackground()的返回值 160. Override161. protectedvoidonPostExecute(ImageAndTextresult)162. /在头部增加新添内容 163. 164. try165. mData.ad

18、d(result);166. 167. /通知程序数据集已经改变,如果不做通知,那么将不会刷新mListItems的集合 168. adapter.notifyDataSetChanged();169. adapter.loadImage();170. /CallonRefreshCompletewhenthelisthasbeenrefreshed. 171. mPullRefreshListView.onRefreshComplete();172. catch(Exceptione)173. /TODO:handleexception 174. setTitle(e.getMessage(

19、);175. 176. 177. super.onPostExecute(result);178. 179. 180. 181. 182. package com.example.try_simpleadapter_new;/* * 完成与服务器通信的下拉刷新 * author harvic */import java.io.BufferedReader;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.List;import org.apache.http.HttpEntity;impor

20、t org.apache.http.HttpResponse;import org.apache.http.NameValuePair;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.methods.HttpPost;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.message.BasicNameValuePair;import org.apache.http.p

21、rotocol.HTTP;import org.json.JSONArray;import com.handmark.pulltorefresh.library.PullToRefreshBase;import com.handmark.pulltorefresh.library.PullToRefreshListView;import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;import android.os.AsyncTask;import android.os.Bundle;import android.text.format.D

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1