How to get checkbox values from server using volley??

646 views.

How to get checkbox values from the server using volley??

 Example API:

{ “data”: [ { “id”: “25”, “MINcost”: “500”, “maxcost”: “50000”, “kind_payment”: “Cash, CreditCards” } ], “status”: 1 }

Asked on June 23, 2017 in android.
Add Comment
1 Answer(s)
337 views.

 JsonObjectRequest objectRequest=new JsonObjectRequest(Request.Method.POST, url, obj,
 new Response.Listener<JSONObject>() {
 @Override
 public void onResponse(JSONObject response) {
 try {
 JsonArray array=response.getJsonArray("data");
 for (int i=0;i<array.size();i++){
 JSONObject obj=array.getJsonObject(i);
 String MINcost=obj.getString("MINcost");
 String maxcost=obj.getString("maxcost");
 String kind_payment=obj.getString("kind_payment");
 //compare string values with CheckBox checked conditions
 //for example
 if(MINcost==500){
 //checkbox related to 500 will be checked 
 checkbox.setChecked(true);
 }else if(MINcost==1000){
 //checkbox related to 1000 will be checked 
 checkbox.setChecked(true);
 }
 }
 } catch (JSONException e) {
 e.printStackTrace();
 }
 }
 },
 new Response.ErrorListener() {
 @Override
 public void onErrorResponse(VolleyError error) {
 Log.e("Error",""+error);
 }
 });
 mRequestQueue.add(objectRequest);
 }
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.