In the main activity I call a API to downlaod most popular movies. When movies are downloaded I call the adatper .notifyDataSetChanged();
This call is made in onPostExecute()
of Asyntask, but there is no changes on recycler.
Part of Main:
mMovieList = new ArrayList<>();
mMovieAdapterRecyclerView = new MovieAdapterRecyclerView(this, mMovieList);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mMovieAdapterRecyclerView);
receiveMovies();
Here is the method I call to load movies and notify the adapter.
private void receiveMovies() {
new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... voids) {
try {
JSONObject response = null;
OkHttpClient client = new OkHttpClient();
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
String mUrl = ConnectionUtils.TRAKT_URL + ConnectionUtils.POPULAR + ConnectionUtils.ALL_INFO;
Request request = new Request.Builder()
.url(mUrl)
.addHeader(ConnectionUtils.TRAKT_API_VERSION, ConnectionUtils.TRAKT_API_VERSION_NUM)
.addHeader(ConnectionUtils.TRAKT_API_KEY, ConnectionUtils.API_KEY)
.addHeader(ConnectionUtils.TRAKT_CONTENT, JSON.toString())
.get()
.build();
Response clientResponse = client.newCall(request).execute();
int code = clientResponse.code();
String responseJson = clientResponse.body().string();
Gson gson = new Gson();
Type listType = new TypeToken<List<Movie>>() {
}.getType();
mMovieList = gson.fromJson(responseJson, listType);
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
@Override
protected void onPostExecute(Boolean aBoolean) {
if(aBoolean) {
mMovieAdapterRecyclerView.notifyDataSetChanged();
}
}
}.execute();
}
The request to the API is correct and I get the information, because when I debug, I can see it.
How can I made it refresh?
UPDATE