from a wordpress site, using json rest api, we get the json of the whole site. I want to load the json of first 10 posts from all category for android. I am using volley to load the json array and it is failing to load the whole array response as it is huge is size. I want first 10 posts and when I click load more I want the json of 11th post to 20th post. can I do so?
currently my url is like http://www.example.com/wp-json/posts
I am requesting in following code
JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET,
baseUrl,
(String) null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d("json",response.toString());
listRecentPost = parseJsonResponse(response);
Log.d("LSN", listRecentPost.isEmpty() + "");
// If any data is avialable
if (!listRecentPost.isEmpty()) {
postAdapter.setRecentPost(listRecentPost);
postAdapter.notifyDataSetChanged();
/*
suppose data connection is off so error image and text will show
* but when my connection will be okk then i need to disable this image and error text
* */
errorImage.setVisibility(View.GONE);
errorMsg.setVisibility(View.GONE);
}
else {
errorMsg.setVisibility(View.VISIBLE);
errorMsg.setText("No Post Available");
}
//disable loading icon
swipeRefreshLayout.setRefreshing(false);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("LSN", error.toString() + "VolleyError");
// enable error iamge and text
errorImage.setVisibility(View.VISIBLE);
errorMsg.setVisibility(View.VISIBLE);
if (error instanceof TimeoutError || error instanceof NoConnectionError) {
errorMsg.setText(error.toString());
} else if (error instanceof AuthFailureError) {
errorMsg.setText(error.toString());
} else if (error instanceof ServerError) {
errorMsg.setText(error.toString());
} else if (error instanceof NetworkError) {
errorMsg.setText(error.toString());
} else if (error instanceof ParseError) {
errorMsg.setText(error.toString());
}
//again try to load data after 30 seconds
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
swipeRefreshLayout.setRefreshing(false);
swapeRefresh();
}
}, 30000);
}
});
Currently I got an exception like com.android.volley.TimeoutError
And What the parameter requestBody does in JsonArrayRequest ? why we use null here?
explaining with codes will be better for me.
Thanks in advance.