Android Volley Post Request - Workaround for JsonArrayRequest -
i understand post requests using jsonarrayrequest not available out of box volley, saw post here talked adding constructor handle this. implementation this:
public jsonarrayrequest(int method, string url, jsonobject jsonrequest, listener<jsonarray> listener, errorlistener errorlistener) { super(method, url, (jsonrequest == null) ? null : jsonrequest.tostring(), listener, errorlistener); }
how go adding constructor? above question mentions placing in volley tool library. imported volley .jar, i'm not sure how add together constructor this, or if best approach. help much appreciated.
edit
i've created next class override , constructor suggested. here class:
public class postjsonarrayrequest extends jsonarrayrequest { @override protected map<string, string> getparams() throws authfailureerror { hashmap<string, string> params = new hashmap<string, string>(); params.put("name", "value"); homecoming params; } public postjsonarrayrequest(int method, string url, jsonobject jsonrequest, listener<jsonarray> listener, errorlistener errorlistener) { super(method.post, url, null, listener, errorlistener); } }
on line calling super i'm getting the constructor jsonarrayrequest(int, string, null, response.listener<jsonarray>, response.errorlistener) undefined
how right this?
create class , extend jsonarrayrequest
override
@override protected map<string, string> getparams() throws authfailureerror { hashmap<string, string> params = new hashmap<string, string>(); params.put("name", "value"); homecoming params; }
and add together new constructor , in phone call
super(method.post, url, null, listener, errorlistener);
or utilize class
public class postjsonarrayrequest extends jsonrequest<jsonarray> { /** * creates new request. * @param url url fetch json * @param listener listener receive json response * @param errorlistener error listener, or null ignore errors. */ public postjsonarrayrequest(string url, response.listener<jsonarray> listener, response.errorlistener errorlistener) { super(method.post, url, null, listener, errorlistener); } @override protected map<string, string> getparams() throws authfailureerror { hashmap<string, string> params = new hashmap<string, string>(); params.put("name", "value"); homecoming params; } @override protected response<jsonarray> parsenetworkresponse(networkresponse response) { seek { string jsonstring = new string(response.data, httpheaderparser.parsecharset(response.headers)); homecoming response.success(new jsonarray(jsonstring), httpheaderparser.parsecacheheaders(response)); } grab (unsupportedencodingexception e) { homecoming response.error(new parseerror(e)); } grab (jsonexception je) { homecoming response.error(new parseerror(je)); } } }
android android-volley
No comments:
Post a Comment