i have got onload more functionality in my app, but when i reach the end of list new items are loaded but the list automatically scrolls to the start of the list.
this is the onload function:
recyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener(mLayoutManager) {
@Override
public void onLoadMore(int current_page, int position) {
// do something...
Log.d("Yaeye!", "HElloyoyo");
SuperHeroes superHero = listSuperHeroes.get(position);
Log.d("we want url", superHero.getImageUrl());
imgoffset = superHero.getImageUrl();
// Do something
getData(0);
}
});
here is the parsing of the data received from the server :
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
//Dismissing progress dialog
// loading.dismiss();
//calling method to parse json array
parseData(response);
adapter.notifyDataSetChanged();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
//Creating request queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
//Adding request to the queue
requestQueue.add(jsonArrayRequest);
}
public int z;
//This method will parse json data
private int parseData(JSONArray array){
for(int i = 0; i<array.length(); i++) {
SuperHeroes superHero = new SuperHeroes();
CardAdapter car = new CardAdapter();
JSONObject json = null;
try {
json = array.getJSONObject(i);
superHero.setImageUrl(json.getString(Config.TAG_IMAGE_URL));
superHero.setProUrl(json.getString("pro_pic"));
Img =json.getString(Config.TAG_IMAGE_URL);
superHero.setName(json.getString(Config.TAG_NAME));
superHero.setRank(json.getInt(Config.TAG_RANK));
superHero.setstat(false);
Log.d("test",Img);
car.setImageUrl(Img);
} catch (JSONException e) {
e.printStackTrace();
}
adapter.notifyItemInserted(listSuperHeroes.size());
listSuperHeroes.add(superHero);
// adapter.notifyDataSetChanged();
loading=false;
}
please help, its urgent and i have spent alot of time on this app already.