我在開發的Android應用程序中有一個GridView
,我從API獲取這個GridView
的數據並將API數據存儲到本地數據庫中,然後將其顯示在GridView
。我的問題是,當我第一次顯示數據時,它的確定,但是當我重新啓動應用程序的GridView
時,會發生重複數據。stop當從api顯示數據到gridview時重複數據android
JsonArrayRequest movieReq = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString());
hidePDialog();
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
JSONObject obj = response.getJSONObject(i);
Movie movie = new Movie();
movie.setTitle(obj.getString("title"));
movie.setThumbnailUrl(obj.getString("image"));
// adding movie to movies array
movieList.add(movie);
} catch (JSONException e) {
e.printStackTrace();
}
}
// notifying list adapter about data changes
// so that it renders the list view with updated data
adapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
hidePDialog();
}
});
如何在我的GridView
中阻止此問題?