使用到的主要内容:

1、Json 解析网络数据

2、异步任务加载图片和数据

3、ListView 的内存空间优化(ConvertView)和运行时间优化(ViewHolder)

4、ListView 滚动监听实现分页加载数据

5、动态定义 布局和控件(想实现下拉刷新,好像不是这样实现的..)

  .......

 

HttpUtil 工具类网络申请数据(用 Gson 解析)  

--- 别忘记添加网络权限 

<uses-permission android:name="android.permission.INTERNET"/>
 1 package com.dragon.android.a09_09;
 2 
 3 import java.io.ByteArrayOutputStream;
 4 import java.io.IOException;
 5 import java.io.InputStream;
 6 import java.net.HttpURLConnection;
 7 import java.net.URL;
 8 
 9 /**
10  * Created by Auser on 2016/9/7.
11  */
12 public class HttpUtil {
13 
14     public static byte[] loadByte(String url){
15 
16         HttpURLConnection conn = null;
17         InputStream is = null;
18         ByteArrayOutputStream baos = null;
19         try {
20             conn = (HttpURLConnection) new URL(url).openConnection();
21             if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
22                 is = conn.getInputStream();
23                 baos = new ByteArrayOutputStream();
24 
25                 byte[] buffer = new byte[1024];
26                 int len = -1;
27                 while ((len = is.read(buffer)) != -1) {
28                     baos.write(buffer,0,len);
29                 }
30                 return baos.toByteArray();
31             }
32         } catch (IOException e) {
33             e.printStackTrace();
34         } finally {
35             try {
36                 if (baos!=null){
37                     baos.flush();
38                     baos.close();
39                 }
40                 if (is != null) {
41                     is.close();
42                 }
43                 if (conn != null) {
44                     conn.disconnect();
45                 }
46             } catch (IOException e) {
47                 e.printStackTrace();
48             }
49         }
50         return null;
51     }
52 
53 }
HttpUtil

相关文章: