Am having one doubt am fetching records from server using volley and saving it in sqlite and setting adapter by quering getlist but it is not displaying the result instantaneously i need to go back and come again to see the newly updated data how to display that record instantly after inserting it in sqlite let me post my code:
Here is the volley code for fetching records from server:
JsonObjectRequest jsonObjRequest = new JsonObjectRequest(Request.Method.GET, params[0], new JSONObject(),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
String server_response = response.toString();
try {
JSONObject json_object = new JSONObject(server_response);
JSONArray json_array = new JSONArray(json_object.getString("AccountPageLoadAccountListResult"));
for (int i = 0; i < json_array.length(); i++) {
Model_Account modelobjs = new Model_Account();
JSONObject json_arrayJSONObject = json_array.getJSONObject(i);
modelobjs.setCompany_group(json_arrayJSONObject.getString("CompanyName"));
modelobjs.setState(json_arrayJSONObject.getString("Region"));
account_sf_db.InsertorUpdate(modelobjs);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getBaseContext(), error.toString(), Toast.LENGTH_SHORT).show();
}
});
queue.add(jsonObjRequest);
Here is the adapter where am setting adapter from sqlite android:
List<ModelClass>listobj=new Arraylist<Modelclass>();
listobj=account_sf_db.list();
accountListAdapter = new AccountListAdapter(listobj, getApplicationContext());
recyclerView.setAdapter(accountListAdapter);
Purpose for this is to handle offine capablity even during offine we must access it using sqlite
Aucun commentaire:
Enregistrer un commentaire