Am having one doubt am fetching data from server and inserting into sqlite and need to diplay immediately from server by querying list in sqlitehelper and setting it as adapter to display recycerler but i cannot get it instantly i need to go back and come again to see that data what i need to get is when i press button instantly need to set adapter from sqlite android how can i do this:
Here is my code:
RequestQueue queue = Volley.newRequestQueue(getBaseContext());
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 where am setting adapter:
List<Model>listobj=new Arraylist<>();
listobj = account_sf_db.list();
accountListAdapter = new AccountListAdapter(listobj, getApplicationContext());
recyclerView.setAdapter(accountListAdapter);
accountListAdapter.notifydatasetchanger();
How can i get data instantly when i click button how to do this!!
Aucun commentaire:
Enregistrer un commentaire