Android : android http request with volley.insert information tu sqlite

on Monday, February 16, 2015


i use volley to parse json and insert all information in database.i successfully parsed json and i also inserted in database.but i have one problem. in my json contains 1000 items and i inserted all items in database and my progress dialog stopped,but showing... how i can write code to can show progress dialog while i inserted all items in my database(same as asynctask)



private void makevillagelistRequest() {

showpDialog();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.GET,
urlGetvillagelist, null, new Response.Listener<JSONObject>() {

@Override
public void onResponse(JSONObject response) {
Log.e("TAG", response.toString());

try {

JSONArray mainjsonArray = response
.getJSONArray("Items");
for (int i = 0; i < mainjsonArray.length(); i++) {
JSONObject j_object = mainjsonArray
.getJSONObject(i);
System.out.println();
Log.e("City", j_object.getString("City"));

Log.e("Village", j_object.getString("Village"));


int branchid = Integer.parseInt(j_object
.getString("BranchId"));
System.out.println(branchid);

int id = Integer.parseInt(j_object
.getString("Id"));
System.out.println(id);

if (d_helper.InsertVillageList_Tablet_Table(id,
j_object.getString("Village"),
j_object.getString("City"), branchid) == true) {
Toast.makeText(getApplicationContext(),
"Added", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),
"something wrong",
Toast.LENGTH_SHORT).show();
}


}

} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
hidepDialog();
}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("TAG", "Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
// hide the progress dialog
hidepDialog();
}
});

// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq);

jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(15000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq);
}


if anyone knows solution please help me thanks


0 comments:

Post a Comment