Android Handler

{"data":
{"blogs":
[{"albid":"1733789","albnm":"\u3002\u63d2\u753b\u83cc\uff5e","ava":"http://img4.duitang.com/uploads/people/201211/02/20121102205120_UYWeX.thumb.24_24_c.jpeg","buylnk":"","cmts":[],"common":false,"favc":69,"good":false,"id":63983188,"iht":256,"isrc":"http://img4.duitang.com/uploads/item/201211/17/20121117083033_aukUm.thumb.200_0.jpeg","msg":"\u753b\u98ce\u597d\u597d","photo_id":5638331,"price":0,"repc":0,"rid":53486782,"ruid":841644,"sta":0,"uid":1053025,"unm":"\u96c1\u4ea6\u4ea6\u4ea6\u4ea6","zanc":0},
{"albid":"1733789","albnm":"\u3002\u63d2\u753b\u83cc\uff5e","ava":"http://img4.duitang.com/uploads/people/201211/02/20121102205120_UYWeX.thumb.24_24_c.jpeg","buylnk":"","cmts":[],"common":false,"favc":174,"good":false,"id":63983171,"iht":337,"isrc":"http://img4.duitang.com/uploads/item/201206/24/20120624094220_wPCRZ.thumb.200_0.jpeg","msg":"\u590f\u8fbe \u7684 \u5c06\u7231","photo_id":3536450,"price":0,"repc":0,"rid":33119557,"ruid":423109,"sta":0,"uid":1053025,"unm":"\u96c1\u4ea6\u4ea6\u4ea6\u4ea6","zanc":0},
{"albid":"1733789","albnm":"\u3002\u63d2\u753b\u83cc\uff5e","ava":"http://img4.duitang.com/uploads/people/201211/02/20121102205120_UYWeX.thumb.24_24_c.jpeg","buylnk":"","cmts":[],"common":false,"favc":36,"good":false,"id":61025918,"iht":287,"isrc":"http://img4.duitang.com/uploads/item/201202/13/20120213114146_EUjA8.thumb.200_0.jpg","msg":"Eno.\uff08\u4f55\u4f55\u821e\uff09\uff0c\u4e2d\u56fd\u77e5\u540d\u63d2\u753b\u5e08\u3002\u753b\u98ce\u4ee5\u624b\u7ed8\u6c34\u5f69\u4e3a\u4e3b\u30022002\u5e74\u4ee5\u300a\u5750\u706b\u8f66\u5230\u6211\u7684\u5bc2\u9759\u8857\u300b\u4e8e\u6f2b\u53cb\u6742\u5fd7\u51fa\u9053\u3002\u76ee\u524d\u5df2\u51fa\u7248\u753b\u96c6\u6709\u300a\u534e\u76d6\u4e4b\u6708\u300b\u300a\u94f6\u83b2\u82b1\u300b\u300a\u7a7a\u8749\u4e0e\u8bd7\u300b\u7b49\u3002","photo_id":1551694,"price":0,"repc":0,"rid":18687755,"ruid":308317,"sta":0,"uid":1053025,"unm":"\u96c1\u4ea6\u4ea6\u4ea6\u4ea6","zanc":0}],
"has_next":true,"hasrp":true,"nopth":true,"pgsource":"_","piclm":false},
"success":true}

json = Helper.getStringFromUrl(url);

JSONObject newsObject = new JSONObject(json);
JSONObject jsonObject = newsObject.getJSONObject(“data“);
JSONArray blogsJson = jsonObject.getJSONArray(“blogs“);
for (int i = 0; i < blogsJson.length(); i++) {
JSONObject newsInfoLeftObject = blogsJson.getJSONObject(i);
DuitangInfo newsInfo1 = new DuitangInfo();
newsInfo1.setAlbid(newsInfoLeftObject.isNull(“albid”) ? “”: newsInfoLeftObject.getString(“albid”));
newsInfo1.setIsrc(newsInfoLeftObject.isNull(“isrc”) ? “”: newsInfoLeftObject.getString(“isrc”));
newsInfo1.setMsg(newsInfoLeftObject.isNull(“msg”) ? “”: newsInfoLeftObject.getString(“msg”));
duitangs.add(newsInfo1);
}

在线程之间传递数据

使用Handler对象不但可以给本线程发送消息,还可以给其他线程发送消息,前提是需要获得其他线程的Handler对象。前台线程创建一个后台线程,并把前台线程的Handler对象传递给后台线程,后台线程就可以通过该Handler对象向前台线程发送消息,报告后台数据处理的进度。

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

生活在西班牙

自己动手丰衣足食

BlueAsteroid

Just another WordPress.com site

Jing's Blog

Just another WordPress.com site

Start from here......

我的心情魔方

天才遠私廚

希望能做一個分享各種資訊的好地方

语义噪声

西瓜大丸子汤的博客

笑对人生,傲立寰宇

Just another WordPress.com site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision

datarazzi

Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness

槑烎

1,2,∞

Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: