Simple use of Android network request volley

Source: Internet
Author: User

Download to local jar package or import online, jar address: Link: http://pan.baidu.com/s/1gf3VZAb Password: Mmye

//Defining VariablesPrivateRequestqueue mqueue=volley.newrequestqueue (context);//specific method of request

/*
* Parameter 1: request mode, Post,get, etc.
* Parameter 2: Request path
*/Stringrequest stringrequest =NewStringrequest (Request.Method.POST, Networkurl.getrecord,NewResponse.listener<string>() {
       / * JSON string returned after successful request, the string is not encrypted, so bind the object directly * /@Override Public voidOnresponse (String s) {userentity userentity=Newuserentity (); LOG.D ("TAG", s.tostring ()); LOG.E ("Reocrd Home", "Home data record----------:" +s.tostring ()); Try{jsonobject Jo=NewJsonobject (s); /*parsing the outermost data*/String He= Jo.getjsonarray ("Data"). toString (); /*parse directly into a collection of objects*/List<RecordEntity> entities = Json.parsearray (he, recordentity.class); List.clear (); for(recordentity entity:entities) {recordentity recordentity=Newrecordentity (Entity.getid (), Entity.getuid (), Entity.getcontent (), entity.getaddress (), Entity.getfile (), Entity.getfiletype (), entity.getfiled Uration (), Entity.getcategoryid (), Entity.getaddtime (), Entity.getcomments (), Entity.getlikes (), Entity.getlikenum ()); LOG.E ("E", "---------------tiem00000000:" +entity.getaddtime ()); List.add (recordentity); }//Lvlist.notifyall ();adapter =NewRecordadapter (Locationapplication.getcontext (), list); Lvlist.setadapter (adapter); } Catch(jsonexception e) {e.printstacktrace (); } } }, NewResponse.errorlistener () {@Override Public voidOnerrorresponse (Volleyerror volleyerror) {}}) {
      / * Request a parameter to pass * /@OverrideprotectedMap<string, string> getparams ()throwsAuthfailureerror {Map<string, string> map =NewHashmap<string, string>(); Map.put ("id", "1"); returnmap; } }; Mqueue.add (stringrequest);/*Request Data*/ }

Simple use of Android network request volley

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.