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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

PullToRefresh使用详解实现异步加载的下拉刷新列表文档格式.docx

1、org.apache.http.impl.client.DefaultHttpClient;17. importorg.apache.http.message.BasicNameValuePair;18. importorg.apache.http.protocol.HTTP;19. importorg.json.JSONArray;20. 21. 22. importcom.handmark.pulltorefresh.library.PullToRefreshBase;23. importcom.handmark.pulltorefresh.library.PullToRefreshLis

2、tView;24. importcom.handmark.pulltorefresh.library.PullToRefreshBase.Mode;25. importcom.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;26. 27. importandroid.os.AsyncTask;28. importandroid.os.Bundle;29. importandroid.text.format.DateUtils;30. importandroid.util.Log;31. importandro

3、id.widget.ListView;32. importandroid.app.ListActivity;33. 34. publicclassMainActivityextendsListActivity35. 36. privateStringserverIP=http:/222.195.151.19;37. ListmData;38. PullToRefreshListViewmPullRefreshListView;39. ImageAndTextListAdapteradapter=null;40. Override41. publicvoidonCreate(Bundlesave

4、dInstanceState)42. super.onCreate(savedInstanceState);43. setContentView(R.layout.activity_main);44. 45. mPullRefreshListView=(PullToRefreshListView)findViewById(R.id.pull_refresh_list);46. 47. /设定下拉监听函数 48. mPullRefreshListView.setOnRefreshListener(newOnRefreshListener()49. 50. onRefresh(PullToRefr

5、eshBaserefreshView)51. labelDateUtils.formatDateTime(getApplicationContext(),System.currentTimeMillis(),52. DateUtils.FORMAT_SHOW_TIME|DateUtils.FORMAT_SHOW_DATEDateUtils.FORMAT_ABBREV_ALL);53. 54. /UpdatetheLastUpdatedLabel 55. refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);56. 57.

6、Log.d(msg,this=+this);58. Doworktorefreshlisthere. 59. newGetDataTask().execute();60. 61. 62. );63. 64. mPullRefreshListView.setMode(Mode.PULL_FROM_END);设置底部下拉刷新模式 65. /传参生成适配器 66. mDatagetData();67. ListViewactualListViewmPullRefreshListView.getRefreshableView();68. adapterImageAndTextListAdapter(t

7、his,mData,actualListView);69. 70. 设置适配器 71. actualListView.setAdapter(adapter);72. 73. 74. getData()75. /创建默认的httpClient实例.76. DefaultHttpClienthttpclientDefaultHttpClient();77. HttpResponseresponsenull;78. HttpEntityentity79. 80. StringBuilderbuilderStringBuilder();81. JSONArrayjsonArray82. 83. Arr

8、ayList();84. 85. try86. 创建httpost.访问本地服务器网址87. HttpPosthttpostHttpPost(serverIP+/try_an_server/index.php);88. 89. /构造POST方法的name:value参数对 90. ListvpsArrayList91. /将参数传入post方法中 92. vps.add(newBasicNameValuePair(action,insert);93. name进去了94. 95. httpost.setEntity(newUrlEncodedFormEntity(vps,HTTP.UTF_8

9、);96. httpclient.execute(httpost);/执行 97. 98. if(response.getEntity()!null)99. /如果服务器端JSON没写对,这句是会出异常,是执行不过去的 100. BufferedReaderreaderBufferedReader(newInputStreamReader(response.getEntity().getContent();101. sreader.readLine();102. for(;reader.readLine()103. builder.append(s);104. 105. Log.i(build

10、er.toString+builder.toString();106. 107. JSONArray(builder.toString();108. (inti0;jsonArray.length();i+)109. if(jsonArray.getJSONObject(i).getInt(id)=1)110. name=jsonArray.getJSONObject(i).getString(111. info=jsonArray.getJSONObject(i).getString(info112. PicName=jsonArray.getJSONObject(i).getString(

11、photo113. picURL=serverIP+/try_an_server/+PicName+.jpg114. 115. ImageAndTextitem=newImageAndText(picURL,name,info);116. list.add(item);117. 118. 119. 120. catch(Exceptione)121. e.printStackTrace();122. finally123. try124. (entity125. 126. httpclient.getConnectionManager().shutdown();/关闭连接 127. /这两种释

12、放连接的方法都可以 128. 129. 130. TODOAuto-generatedblock 131. 132. 133. 134. 135. returnlist;136. 137. 138. 139. 140. 141. GetDataTaskAsyncTaskVoid,142. 143. /后台处理部分 144. 145. protecteddoInBackground(Void.params)146. Simulatesabackgroundjob. 147. item148. 149. ImageAndText(serverIP+/try_an_server/xizang.jpg

13、sssssss150. 151. TODO:handleexception 152. setTitle(map出错了153. 154. 155. item;156. 157. 158. /这里是对刷新的响应,可以利用addFirst()和addLast()函数将新加的内容加到LISTView中 159. /根据AsyncTask的原理,onPostExecute里的result的值就是doInBackground()的返回值 160. 161. onPostExecute(ImageAndTextresult)162. /在头部增加新添内容 163. 164. 165. mData.add(r

14、esult);166. 167. /通知程序数据集已经改变,如果不做通知,那么将不会刷新mListItems的集合 168. adapter.notifyDataSetChanged();169. adapter.loadImage();170. CallonRefreshCompletewhenhasbeenrefreshed. 171. mPullRefreshListView.onRefreshComplete();172. 173. 174. setTitle(e.getMessage();175. 176. 177. super.onPostExecute(result);178.

15、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;import org.apache.http.HttpResponse;import org.apache.h

16、ttp.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.protocol.HTTP;import org.json.JSONArray;import com.

17、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.Dat

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

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