vendredi 11 mars 2016

How to update UI whenever sqlite database value change?

Let me explain my problem after inserting value into sqlite table need to display that record instantly how can i do this i have done my project with sqliteonehelper class and done my queries according to my requirements now if i need to update UI instantly i have read that it can be done only through content provider is it necessary to implement provider or i can be done with cursor loader or content observer am bit confused with this!! any help i appreciate so far what i have tried is:

 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"));
                                modelobjs.setAccountID(json_arrayJSONObject.getInt("AccountID"));
                                account_sf_db.InsertorUpdate(modelobjs);
                                accountListAdapter.notifyDataSetChanged();



                            }
                        }  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);

Need to set adapter by quering list in sqliteonehelper class but i need to go back and come again to refresh view the recyclerview i need to see it immediately how can i do this can anybody help me

Aucun commentaire:

Enregistrer un commentaire