JSON data analytic simulation of the United States-_android interface display

Source: Internet
Author: User
<?xml version= "." Encoding= "utf-"?> <relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" DP "android:background=" @android: Color/white " > <imageview android:id= "@+id/list_icon_img" Android:layout_width= "DP" android:layout_height= "DP" ANDROID:SRC
= "@drawable/ic_launcher"/> <textview android:id= "@+id/list_name_txt" android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" android:layout_torightof= "@id/list_icon_img" android:singleline= "true"
android:text= "Takeshima Hotel" android:textcolor= "@android: Color/background_dark" android:textsize= "sp"/> <textview Android:id= "@+id/list_coupe_txt" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android : layout_below= "@id/list_name_txt" android:layout_torightof= "@id/list_icon_img" android:singleline= "true" Android: text= "Online reservation for discount" android:textcolor= "@android: Color/holo_red_dark" android:textsize= "sp"/> &lT TextView android:id= "@+id/list_distance_txt" android:layout_width= wrap_content "android:layout_height=" Wrap_ Content "android:layout_alignparentbottom=" true "android:layout_alignparentright=" true "Android:layout_ Marginright= "DP" android:drawableleft= "@drawable/info_map" android:text= ". K" android:textcolor= "@android: color/ Tab_indicator_text "android:textsize=" sp "/> <textview android:id=" @+id/list_location_txt "Android:layout_ Width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_alignparentbottom= "true" Android:layout_ toleftof= "@id/list_distance_txt" android:layout_torightof= "@id/list_icon_img" android:singleline= "true" Android: Text= "Lao Cheng Cheng Lu, Chengdu City High-tech zone, Chengdu, Sichuan Province, China" the old urban high-tech zone, the high new district, the mature urban High-tech district, "android:textcolor=" @android: Color/tab_indicator_text "android:
textsize= "sp"/>-<relativelayout android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_alignparentright= "true" android:layout_alignparenttop= "true" > <imageview android:id= "@+id/"List_card_img "android:layout_width=" wrap_content "android:layout_height=" wrap_content "android:src=" @drawable Near_card "/> <imageview android:id= @+id/list_group_img" android:layout_width= "Wrap_content" Android:layout_ height= "Wrap_content" android:layout_torightof= "@id/list_card_img" android:src= "@drawable/near_group"/> < ImageView android:id= "@+id/list_ticket_img" android:layout_width= wrap_content "android:layout_height=" Wrap_ Content "android:layout_torightof=" @id/list_group_img "android:src=" @drawable/near_ticket "/> </ Relativelayout> </RelativeLayout>

Run Effect chart:

Requires four LIB packages: parsing JSON Gson packets, parsing JSON data from a network address to a string of asynchronous network resolution tools Asynchttpclient, etc.

Download address: Click to download

The code is as follows:

Package com.lixu.testjsonall;
Import java.util.ArrayList;
Import java.util.List;
Import Com.google.gson.Gson;
Import com.loopj.android.http.AsyncHttpClient;
Import Com.loopj.android.http.TextHttpResponseHandler;
Import Com.squareup.picasso.Picasso;
Import android.app.Activity;
Import Android.content.Context;
Import Android.os.Bundle;
Import Android.view.LayoutInflater;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.view.Window;
Import Android.widget.ArrayAdapter;
Import Android.widget.ImageView;
Import Android.widget.ListView;
Import Android.widget.TextView;
Import Android.widget.Toast;
Import Cz.msebera.android.httpclient.Header; public class Mainactivity extends activity {private String Net_url = "Http://.../json/around"; private ListView LV; priva
Te Myadapter mmyadapter;
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Requestwindowfeature (Window.feature_no_title);
Setcontentview (R.layout.activity_main); Lv = (ListView) Findviewbyid (r.id.lv);
Mmyadapter = new Myadapter (this,-);
Lv.setadapter (Mmyadapter);
Asynchttpclient AHC = new Asynchttpclient (); Ahc.get (Net_url, New Texthttpresponsehandler () {//resolves JSON data by network address to string type @Override public void onsuccess (int arg, head
Er[] arg, string arg {//Parse JSON file from string Gson Gson = new Gson ();
Infoall Infoall = Gson.fromjson (ARG, infoall.class);
Info info = infoall.getinfo ();
list<merchantkey> Mmerchantkey = Info.getmerchantkey ();
Mmyadapter.setlist (Mmerchantkey); @Override public void onfailure (int arg, header[] arg, String ARG, throwable Arg) {Toast.maketext (getapplicationcontext (), "Wrong!"
",). Show ();}}); Private class Myadapter extends Arrayadapter {private layoutinflater flater; private list<merchantkey> data = new A
Rraylist<merchantkey> ();
private context; Public Myadapter (context, int resource) {Super (context, resource); this.context = context; Flater = Layoutinflate
R.from (context); } public void SetlisT (list<merchantkey> data) {this.data = Data mmyadapter.notifydatasetchanged ()} @Override public View GetView T position, View Convertview, ViewGroup parent) {if (Convertview = = null) Convertview = Flater.inflate (R.layout.list, nul
L);
TextView Biaoti = (TextView) Convertview.findviewbyid (r.id.list_name_txt);
Biaoti.settext (Data.get (position). GetName ());
TextView Biaoti = (TextView) Convertview.findviewbyid (r.id.list_coupe_txt);
Biaoti.settext (Data.get (position). Getcoupon ());
TextView Dizhi = (TextView) Convertview.findviewbyid (r.id.list_location_txt);
Dizhi.settext (Data.get (position). GetLocation ());
TextView juli = (TextView) Convertview.findviewbyid (r.id.list_distance_txt);
Juli.settext (Data.get (position). Getdistance ());
ImageView jpg = (imageview) Convertview.findviewbyid (r.id.list_icon_img);
Picasso.with. Load (data.get (position). Getpicurl ()). into (JPG);
ImageView Tuan = (ImageView) Convertview.findviewbyid (r.id.list_group_img); ImageView Quan = (imageview) ConvertView.findviewbyid (R.ID.LIST_TICKET_IMG);
ImageView ka = (imageview) Convertview.findviewbyid (r.id.list_card_img); if (Data.get (position). Getgrouptype (). Equals ("YES")) {tuan.setvisibility (view.visible);} else {tuan.setvisibility (
View.gone); } if (Data.get (position). Getcardtype (). Equals ("YES")) {ka.setvisibility (view.visible);} else {ka.setvisibility (
View.gone);
} if (Data.get (position). Getcoupontype (). Equals ("YES")) {quan.setvisibility (view.visible);} else {
Quan.setvisibility (View.gone);
return convertview;
@Override public int GetCount () {return data.size ();}}
} package Com.lixu.testjsonall;
Import java.util.List;  public class Info {private list<merchantkey> merchantkey, public list<merchantkey> Getmerchantkey () {return
Merchantkey; 
public void Setmerchantkey (list<merchantkey> merchantkey) {this.merchantkey = Merchantkey;}}
Package com.lixu.testjsonall; public class Infoall {private info info. GetInfo () {return info.} public VoiD SetInfo (Info info) {this.info = info;}}
Package com.lixu.testjsonall; public class Merchantkey {private string name; private string coupon; private string location; private string Distance p
Rivate String Picurl;
Private String Coupontype;
Private String Cardtype;
Private String GroupType; public string GetName () {return name.} public void SetName (string name) {this.name = name;} public string Getcoupon ()
{return coupon;} public void Setcoupon (string coupon) {This.coupon = coupon.} public String GetLocation () {return location;} public Voi D setlocation (string location) {this.location = location;} public String getdistance () {return distance;} public void Setdistance (string distance) {this.distance = distance;} public String Getpicurl () {return picurl;} public void Setpic URL (String picurl) {this.picurl = Picurl;} public String Getcoupontype () {return coupontype;} public void Setcoupontyp E (String coupontype) {this.coupontype = Coupontype;} public String getcArdtype () {return cardtype.} public void Setcardtype (String cardtype) {this.cardtype = Cardtype;} public String Getgro  Uptype () {return grouptype.} public void Setgrouptype (String grouptype) {this.grouptype = GroupType;}}

XML file:

 <linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android" xmlns: tools= "Http://schemas.android.com/tools" android:layout_width= "match_parent" android:layout_height= "Match_parent" "Android:orientation=" vertical "tools:context=" com.lixu.testjsonall.MainActivity "> <linearlayout android: Layout_width= "Match_parent" android:layout_height= "wrap_content" android:background= "@drawable/title_log" Android : orientation= "Horizontal" > <imageview android:id= "@+id/fanhui" Android:layout_width= "DP" Android:layout_ Height= "DP" android:layout_gravity= "center" android:src= "@drawable/btn_back"/> <textview android:layout_
Width= "Wrap_content" android:layout_height= "wrap_content" android:layout_gravity= "center" android:text= "My Concern" android:textsize= "sp"/> </LinearLayout> <listview android:id= "@+id/lv" android:layout_width= "Match_" Parent "android:layout_height=" match_parent "/> </linearlayout> 

Parse the network JSON data, simulate the United States to display relevant content of the interface to introduce you here, I hope to help you.

Then I'll introduce you to the analog JSON data parsing format.

String response =//"{\ code\": \ "1\", \ "desc\": \ "Success\", \ "data\": {\ "showcount\": \ "10\", \ "totalcount\": \ "1\", \ "totalpage\": \ "1\", \ "currpage\": \ "1\", \ "offset\": \ "0\"},\ "apps\": ["//+//" {\ "id\": 1,\ "status\": \ "1\", \ "url\": \ " Www.qq.com\ ", \" rank\ ": \" 1\ "," title\ ": \" qq\ "," createtime\ ": \" 1325088000000\ "," updatetime\ ": \" 1325088000000\ " , \ "remarks\": \ "?? \ ", \" intro\ ": \" Cool music 2012 is cool music for the Android platform tailored professional online music play \ "," isusable\ ": \" 1\ "," isjoint\ ": \" 1\ "," micon\ ": \" http:/ /www.51anzhuo.com.cn/upload/widget/splidapps/m/2011-10/vapk_1.jpg\ ", \" appcount\ ": \" 20\ "," storename\ ": \" Anzhuo \ "},"//+//"{\" id\ ": 2,\" status\ ": \" 1\ ", \" url\ ": \" www.wabang.com\ ", \" rank\ ": \" 1\ "," title\ ": \" Web\ "," Createtime " \ ": \ 1325606400000\", \ "updatetime\": \ "1325606400000\", "remarks\": \ "?? \ ", \" intro\ ": \" The alarm clock, basically other alarm clock functions are covered by the \ "," isusable\ ": \" 1\ "," isjoint\ ": \" 1\ "," micon\ ": \" http:// Www.51anzhuo.com.cn/upload/widget/splidapps/m/2011-10/vapk_1.jpg\ ", \" appcount\ ": \" 20\ "," storename\ ": \" anzhuo\
"}]}"; // }

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.