How To Implement A Proper Scroll In List View To Implement Pagination On Fragment Activity?
I am building an application like techcrunch. I am fetching data from server in JSON format and displaying the data in list view like article title,author name and image. I have ap
Solution 1:
You can try this (I added a line to set the new list position in the last line of onStart())
With this line you can set the new position_
listView.setSelectionFromTop(newPosition, 0);
With the first parameter you set the position, and with the second you set the distnace from the top of the list
@OverridepublicvoidonStart(){
super.onStart();
// calling adapter changes here, just// to avoid getactivity()null// increment current page
current_page += 1;
// Next page requestURL = "http:url&page=" + current_page;
//adapter = new CustomListAdapter(this, movieList);// changing action bar color//getActivity().getActionBar().setBackground(//new ColorDrawable(Color.parseColor("#1b1b1b")));// Creating volley request objJsonArrayRequest movieReq = newJsonArrayRequest(URL,
newResponse.Listener<JSONArray>() {
@OverridepublicvoidonResponse(JSONArray response) {
Log.d(TAG, response.toString());
hidePDialog();
// Parsing jsonfor (int i = 0; i < response.length(); i++) {
try {
JSONObject obj = response.getJSONObject(i);
Movie movie = newMovie();
movie.setDate(obj.getString("date"));
movie.setId(obj.getString("id"));
movieList.add(movie);
int currentPosition = listView.getFirstVisiblePosition();
adapter = newCustomListAdapter(getActivity(), movieList);
adapter.notifyDataSetChanged();
listView.setAdapter(adapter);
listView.setSelectionFromTop(currentPosition + 1, 0);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
},newResponse.ErrorListener() {
@OverridepublicvoidonErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
newAlertDialog.Builder(getActivity())
.setTitle("No Connectivity ")
.setMessage("Please check your internet connectivity!")
.setPositiveButton(android.R.string.yes, newDialogInterface.OnClickListener() {
publicvoidonClick(DialogInterface dialog, int which) {
// continue with delete
}
})
//.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {//public void onClick(DialogInterface dialog, int which) { // do nothing//}//})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
hidePDialog();
}
});
AppController.getInstance().addToRequestQueue(movieReq);
listView.setAdapter(adapter);
//Set the new position
listView.setSelectionFromTop(currentPosition + 1, 0);
}
Post a Comment for "How To Implement A Proper Scroll In List View To Implement Pagination On Fragment Activity?"