I am creating a new android app, I have nearly completed the first screen. However, as soon as I reach the bottom of the screen, instead of loading new data, the app throws me right to the beginning of the page.
The API that I'm using will send the next page when I send a request for the second page. Can you please tell me how can I make the app such that, it automatically sends the request for the second page, before the user reaches the end of the first page.
I'm using volley library along with recyclerView and cardView. Can you please explain clearly as to where am I supposed to make changes, I am new to app development.
Here is the volley request:
private void discoverMovies() {
final ProgressDialog progressDialog = new ProgressDialog(getContext());
progressDialog.setMessage("Fetching Data From DB");
progressDialog.show();
//Requesting the data.....
StringRequest stringRequest = new StringRequest(Request.Method.GET, tempURL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
progressDialog.dismiss();
JSONObject parentObject = new JSONObject(response);
JSONArray parentArray = parentObject.getJSONArray("results");
for (int i = 0; i < parentArray.length(); i++) {
JSONObject object = parentArray.getJSONObject(i);
movieModel model = new movieModel(
object.getString("title"),
object.getString("overview"),
object.getString("release_date"),
object.getString("poster_path"),
object.getInt("id"),
object.getBoolean("adult"),
object.getInt("vote_count"),
object.getDouble("vote_average"),
object.getString("original_language"),
object.getString("backdrop_path")
);
movieModels.add(model);
adapter = new cardViewAdapter(getContext(), movieModels);
recyclerView.setAdapter(adapter);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.dismiss();
Toast.makeText(getActivity(), error.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(getContext());
requestQueue.add(stringRequest);
}