Android-based ListView & amp; Json loading network data, androidlistview

Source: Internet
Author: User

Android-based ListView & Json loading network data, androidlistview

Main content used:

1. parse network data in Json format

2. asynchronous tasks load images and data

3. ConvertView and ViewHolder)

4. The ListView rolling listener enables data loading by PAGE

5. dynamically define the layout and controls (if you want to implement pull-down refresh, it does not seem like this ..)

.......

 

HttpUtil tool network application data (resolved by Gson)

--- Do not forget to add network Permissions

<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 ByteArrayOutputStr Baeam OS = 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

 

Datas class stores the required data (GsonFormat plug-in)

1 package com. dragon. android. a09_09; 2 3 import java. util. list; 4 5/** 6 * Created by Auser on 2016/9/9. 7 */8 public class Datas {9 10/** 11 * code: 99999 12 * data: {"results": [{"action": 0, "actionTime ": 1472219620657, "candidateCount": 85, "cateravuplice": "49", "caterBranchName": "Central City store", "caterBusinessId": "DZ: 2213221", "caterCategories ": "Cinema", "caterCity": "Shenzhen", "caterPhotoUrl": "http://qcloud.dpfile.c Om/pc/EXgo-1x_xBtU9ZucqX7hTSvd27a8ZWYntDVUaMciJtZbnpM9T49yMmnt4yPiPxuwTYGVDmosZWTLal1WbWRW3A.jpg "," caterPlatform ": 1," caterRegions ":" Futian district city center "," caterSPhotoUrl ":" http://qcloud.dpfile.com/pc/EXgo-1x_xBtU9ZucqX7hTSvd27a8ZWYntDVUaMciJtZwpuORpFhuvgx7Yzr27-sHTYGVDmosZWTLal1WbWRW3A.jpg "," caterShopId ": 382401, "caterTelephone": "0755-82801168", "clientStamp": 1472219156, "commentCount": 201, "createTime": 147221962 0657, "credit": 0, "deviceModel": "iPhone", "eventAddress": "G layer, Yijing center city, fuhua Road, Futian district", "eventCity": "0755 ", "eventCityName": "Shenzhen", "eventDateTime": 1473420600000, "eventDescription, I don't know how to do things. \ n doesn't have time, so I'm more interested in setting you up. \ N don't blind BB when eating melons. People in Northeast China don't have such a good temper. \ n will joke and joke, don't pretend to force, \ n is a good-looking advantage. After all, it is an era of facial recognition. \ n but if you are not polite, don't think you are beautiful. \ N ugly people are not terrible, they are afraid that your heart is ugly, do yourself well. \ N everyone has bad money. No one is a bank, but you don't need to do anything. \ N people are mutual. You can help me to help you, \ n, but don't take everything for granted. \ N can be a brother, a friend, and a friend. \ n don't grind. \ N identified ARTIST: Wang Han, Lin Zhiying, Ren xianqi, \ n Xiao yaxuan, Pan zhangbai, Li ronghao. \ N tbd artist: Xu Wei "," eventExpense ": 47," eventKey ":" LFCAEL "," eventLatitude ": 22.53608," eventLocation ":" Jinyi Film City ", "eventLocationUrl": "http://m.dianping.com/shop/2213221? Utm_source = open "," eventlongpolling ": 114.05923," eventName ":" interesting soul go to The Universiade Sports Center to watch Concerts "," eventRegion ":" Futian district city center ", "Category": 1, "feeType": {"desc": "My treat", "field": "MyTreat", "value": 1}, "guarantee ": 0, "id": 827518, "isMark": false, "multi": 0, "opposite": 0, "rechargeCred": 0, "score": 653.0702748285551, "showCount": 3670, "state": 0, "tagId": "3706", "url": "http://www.qingchifan.com/event/detail/827518", "user": {"action": 1, "age": 77, "conste Llation ":" Pisces "," gender ": 1," height ": 180," isOfficial ":" 0 "," lastOnlineTime ":" 1473358886081 "," lat ": 22.54983991655006, "lng": 114.1008416972523, "nick": "Mr. yang "," role2 ":" 0 "," userId ": 127891," userImageUrl ":" http://img2.chouti.com/QIM/2016090901/7dff30c8e35047fda84bec83128af793.jpg "," userKey ":" EFCLME "}," userId ": 127891, "visitorState": 0 },{ "action": 0, "actionTime": 1473378002766, "candidateCount": 1, "cateravuplice ":" 288 "," caterBranchName ":" "," caterBusinessId ":" DZ: 2810071 "," caterCategories ":" buffet "," caterCity ":" Shenzhen ", "caterPhotoUrl": "http://qcloud.dpfile.com/pc/ka5nJiUVP1iEDEInm-5ctFhAg0oTJ6h_JrWwPWyTVSvV-Oie0zXWa0hU-eqGUQgMTYGVDmosZWTLal1WbWRW3A.jpg", "caterPlatform": 1, "caterRegions": "Futian district downtown", "caterSPhotoUrl": "http://qcloud.dpfile.com/pc/ka5nJiUVP1iEDEInm-5ctFhAg0oTJ6h_JrWwPWyTVSsJDGuWFTd4kmkKP90dcyjBTYGVDmos ZWTLal1WbWRW3A.jpg "," caterShopId ": 74869," caterTelephone ":" 0755-21513838 "," clientStamp ": 1473378002086," commentCount ": 5," createTime ": 1473378002766, "credit": 130, "deviceModel": "Android", "eventAddress": "1 floor, Shangri-La Hotel, No. 4088, yitian Road, Futian district", "eventCity": "0755 ", "eventCityName": "Shenzhen", "eventDateTime": 1474362000000, "eventDescription": "character is a rare and precious quality tag in today's society. character determines attitude and Attitude determines behavior, behavior determines the final result. Although the appearance of a woman is attractive, wisdom and humble attitude are indispensable. Otherwise, people will easily show arrogant, vanity and other ugly characteristics. "," EventExpense ": 288," eventKey ":" LGLLED "," eventLatitude ": 22.536156," eventLocation ":" Futian Shangri-La Hotel-fresh coffee cafeteria ", "eventLocationUrl": "http://m.dianping.com/shop/2810071? Utm_source = open "," eventlongpolling ": 114.057," eventName ":" Buffet \ n Buffet "," eventRegion ":" Downtown "," region ": 1, "feeType": {"desc": "My treat", "field": "MyTreat", "value": 1}, "guarantee": 0, "guaranteeCred ": 0, "id": 838810, "isMark": false, "multi": 0, "opposite": 2, "rechargeCred": 0, "score": 510.20296508423274, "showCount": 22, "state": 0, "tagId": "3792", "url": "http://www.qingchifan.com/event/detail/838810", "user": {"action": 1, "age": 28, "constellation": "Aries", "gender": 1, "height": 170, "isOfficial": "0", "lastOnlineTime ": "1473382864509", "lat": 22.650712, "lng": 114.024987, "nick": "menglaike", "role2": "0", "userId": 35965, "userImageUrl": "http://img2.chouti.com/group/2016082810/1942adb39d8b69a37fa0887fd55bab9b.jpg", "userKey": "GAMBA"}, "userId": 35965, "visitorState": 0 },{ "action": 0, "actionTime": 1472372122903, "candidateCount": 76, "cateravuplice": "366", "caterBranchName": "Shenzhen overseas Chinese town store", "caterBusinessId": "DZ: 2723608 ", "caterCategories": "steak Western", "caterCity": "Shenzhen", "caterPhotoUrl": "http://i3.s2.dpfile.com/pc/f14584fdd425d9a5a70f747f7ebcc6fa (700x700)/thumb.jpg", "caterPlatform": 1, "caterRegions": "Nanshan District overseas Chinese town Baishi island itian holiday", "caterSPhotoUrl": "http://i2.s2.dpfile.com/pc/f14584fdd425d9a5a70f747f7ebcc6fa (278x200)/thumb.jpg", "caterShopId": 1120, "caterTelephone ": "0755-86298729", "clientStamp": 1472372124606, "commentCount": 55, "createTime": 1472372122903, "credit": 0, "deviceModel": "Android ", "eventAddress": "3F, yitian holiday Plaza, No. 9028 ShenNan Avenue, Nanshan District", "eventCity": "0755", "eventCityName": "Shenzhen", "eventDateTime": 1473417000000, "eventDescription"

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.