RecyclerView分页不起作用
Posted
技术标签:
【中文标题】RecyclerView分页不起作用【英文标题】:RecyclerView pagination not working 【发布时间】:2017-10-22 22:55:39 【问题描述】:我试图在 RecyclerView 的最后一项之后向下滚动时加载更多项,但没有任何反应。它只在屏幕加载时调用一次,尽管我向下滚动并移至最后一项,但什么也没发生。
下面是我的代码
inspectionRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView_Inspections);
final LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
inspectionRecyclerView.setLayoutManager(mLayoutManager);
inspectionRecyclerView.setOnScrollListener(new EndlessRecyclerOnScrollListener(
mLayoutManager)
@Override
public void onLoadMore(int current_page)
// do somthing...
Log.v("Call", "Load more");
//api call to load more items goes here
);
滚动部分代码
public abstract class EndlessRecyclerOnScrollListener extends
RecyclerView.OnScrollListener
public String TAG = EndlessRecyclerOnScrollListener.class
.getSimpleName();
private int previousTotal = 0;
private boolean loading = true;
private int visibleThreshold = 5;
int firstVisibleItem, visibleItemCount, totalItemCount;
private int current_page = 1;
private LinearLayoutManager mLinearLayoutManager;
public EndlessRecyclerOnScrollListener(
LinearLayoutManager linearLayoutManager)
this.mLinearLayoutManager = linearLayoutManager;
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
super.onScrolled(recyclerView, dx, dy);
visibleItemCount = recyclerView.getChildCount();
totalItemCount = mLinearLayoutManager.getItemCount();
firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();
if (loading)
if (totalItemCount > previousTotal)
loading = false;
previousTotal = totalItemCount;
if (!loading
&& (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold))
// End has been reached
// Do something
current_page++;
onLoadMore(current_page);
loading = true;
public abstract void onLoadMore(int current_page);
请帮帮我。
【问题讨论】:
【参考方案1】:你好,看看有没有帮助
1) 当我开始这个活动时,我将我的数据从服务器存储到名为 activityData 的集合中。
2)activityData 现在有我想要在 RecyclerView 中显示的数据。
3) 我使用活动数据填充 RecyclerView。
4) 现在你要一个scrollListener看看代码
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener()
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState)
super.onScrollStateChanged(recyclerView, newState);
@Override
public void onScrolled(final RecyclerView recyclerView, int dx, int dy)
super.onScrolled(recyclerView, dx, dy);
//activitiesData is collection used to populate the recycler Adapter
activitiesData.remove(activitiesData.size() - 1);
recyclerViewAdapter.notifyItemRemoved(activitiesData.size());
// Make a networking call to get the data on page scrolled
//after you get response
recyclerViewAdapter.notifyDataSetChanged();
);
【讨论】:
【参考方案2】:我使用以下代码,它对我来说工作正常。在您的 api 调用完成后,不要忘记将加载值设置为 FALSE。
public RecyclerView.OnScrollListener getOnScrollListener()
return new RecyclerView.OnScrollListener()
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
if (dy > 0)
visibleItemCount = lm.getChildCount();
totalItemCount = lm.getItemCount();
pastVisibleItem = lm.findFirstVisibleItemPosition();
if (!isLoading)
if ((visibleItemCount + pastVisibleItem) >= totalItemCount)
isLoading = true;
loadNextPage();
;
【讨论】:
【参考方案3】: private boolean loading = true;
int pastVisiblesItems, visibleItemCount, totalItemCount;
int OFFSET = 0;
ArrayList<ServiceModel> voiceSearchArray = new ArrayList<>();
在oncreate中编写代码设置滚动监听
ServiceAdapter = new ServiceAdapter(Home_Activity.this, voiceSearchArray);
linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
recycler_view.setLayoutManager(linearLayoutManager);
recycler_view.setItemAnimator(new DefaultItemAnimator());
recycler_view.setAdapter(ServiceAdapter);
recycler_view.addOnScrollListener(new RecyclerView.OnScrollListener()
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
if (dy > 0) //check for scroll down
visibleItemCount = linearLayoutManager.getChildCount();
totalItemCount = linearLayoutManager.getItemCount();
pastVisiblesItems = linearLayoutManager.findFirstVisibleItemPosition();
if (loading)
if ((visibleItemCount + pastVisiblesItems) >= totalItemCount)
loading = false;
Log.e("Last Item Wow !", "Last Item Wow !");
OFFSET = OFFSET + 10;
CallVoiceSearchResultWebservice();
//Do pagination.. i.e. fetch new data
);
方法是:
private void CallVoiceSearchResultWebservice()
final ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Verifying. Please Wait...");
pDialog.show();
String URL = "http://idot.co.in//android/voice-search";
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest sr = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>()
@Override
public void onResponse(String response)
Log.e("Response", response);
pDialog.dismiss();
if (OFFSET == 0)
voiceSearchArray.clear();
loading = true;
try
JSONObject records = new JSONObject(response);
if (records.getString("status").equals("1"))
JSONArray recordList = records.getJSONArray("recordList");
String image_base_url = records.getString("image_base_url");
for (int i = 0; i < recordList.length(); i++)
JSONObject recordObj = recordList.getJSONObject(i);
ServiceModel serviceModel = new ServiceModel();
serviceModel.setPk_id(recordObj.getString("pk_id"));
serviceModel.setFullname(recordObj.getString("fullname"));
serviceModel.setEmail(recordObj.getString("email"));
serviceModel.setMobile(recordObj.getString("mobile"));
serviceModel.setBusiness_name(recordObj.getString("business_name"));
serviceModel.setAddress(recordObj.getString("address"));
serviceModel.setWebsite(recordObj.getString("website"));
serviceModel.setRating_cnt(recordObj.getString("rating_cnt"));
serviceModel.setPhoneno(recordObj.getString("phoneno"));
serviceModel.setPhoto(image_base_url + recordObj.getString("photo"));
voiceSearchArray.add(serviceModel);
ServiceAdapter.notifyDataSetChanged();
else
Toast.makeText(Home_Activity.this, "No more records Available.", Toast.LENGTH_SHORT).show();
catch (JSONException e)
e.printStackTrace();
, new Response.ErrorListener()
@Override
public void onErrorResponse(VolleyError error)
Log.e("error", error.toString());
pDialog.dismiss();
if (error instanceof TimeoutError || error instanceof NoConnectionError)
Toast.makeText(Home_Activity.this, "Sorry, Please Check your Internet Connection.",
Toast.LENGTH_LONG).show();
else if (error instanceof AuthFailureError)
Toast.makeText(Home_Activity.this, "Sorry, AuthFailureError.",
Toast.LENGTH_LONG).show();
//TODO
else if (error instanceof ServerError)
Toast.makeText(Home_Activity.this, "Sorry, ServerError.",
Toast.LENGTH_LONG).show();
//TODO
else if (error instanceof NetworkError)
Toast.makeText(Home_Activity.this, "Sorry, NetworkError.",
Toast.LENGTH_LONG).show();
//TODO
else if (error instanceof ParseError)
//TODO
// mPostCommentResponse.requestEndedWithError(error);
)
@Override
protected Map<String, String> getParams()
Map<String, String> params = new HashMap<String, String>();
params.put("searchtext", VoiceSearch);
params.put("limit", "10");
params.put("offset", String.valueOf(OFFSET));
// params.put("utype", "");
Log.e("searchtext params", "searchtext params " + params.toString());
return params;
@Override
public Map<String, String> getHeaders() throws AuthFailureError
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/x-www-form-urlencoded");
return params;
;
queue.add(sr);
【讨论】:
【参考方案4】:package com.latest.share.chat.fragments;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.latest.share.chat.MyApplication;
import com.latest.share.chat.R;
import com.latest.share.chat.activities.SearchActivity;
import com.latest.share.chat.adapters.PostViewAdapter;
import com.latest.share.chat.adapters.viewholders.Item;
import com.latest.share.chat.adapters.viewholders.MusicViewHolder;
import com.latest.share.chat.models.Footer;
import com.latest.share.chat.models.PostViewModel;
import com.latest.share.chat.utils.Config;
import com.latest.share.chat.utils.UtilMethods;
import com.volokh.danylo.visibility_utils.calculator.DefaultSingleItemCalculatorCallback;
import com.volokh.danylo.visibility_utils.calculator.ListItemsVisibilityCalculator;
import com.volokh.danylo.visibility_utils.calculator.SingleListViewItemActiveCalculator;
import com.volokh.danylo.visibility_utils.scroll_utils.RecyclerViewItemPositionGetter;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import static android.app.Activity.RESULT_OK;
/**
* A simple @link Fragment subclass.
*/
public class PostViewFragment extends Fragment
private Context mContext;
private ArrayList<Item> list;
private ArrayList<Item> list1;
private ArrayList<Item> final_list;
private RecyclerView recyclerView;
private ProgressBar progressBar;
LinearLayoutManager mLayoutManager;
ListItemsVisibilityCalculator mVideoVisibilityCalculator;
private RecyclerViewItemPositionGetter mItemsPositionGetter;
private int mScrollState = AbsListView.OnScrollListener.SCROLL_STATE_IDLE;
boolean has_next_page = false;
int next_page_no = 1;
PostViewAdapter adapter;
public static final int POST_COMMENT_REQUEST = 201;
private String tag_name;
private String fragment_type;
private String fragment_extra;
private LinearLayout linear_search;
private SwipeRefreshLayout swipeContainer;
private TextView text_retry;
private LinearLayout linear_no_internet;
private TextView text_no_data;
private String following_id = "";
public PostViewFragment()
// Required empty public constructor
public static Fragment Instance(String fragment_type, String fragment_extra)
PostViewFragment fragment = new PostViewFragment();
Bundle bundle = new Bundle();
bundle.putString("fragment_extra", fragment_extra);
bundle.putString("fragment_type", fragment_type);
fragment.setArguments(bundle);
return fragment;
@Override
public void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
fragment_extra = getArguments().getString("fragment_extra");
fragment_type = getArguments().getString("fragment_type");
assert fragment_type != null;
if (fragment_type.equalsIgnoreCase(Config.FRAGEMNT_TYPE_FAMOUS))
tag_name = "get_post_by_famous";
else if (fragment_type.equalsIgnoreCase(Config.FRAGMENT_TYPE_FOLLOWERS))
tag_name = "get_posts_by_followers";
else if (fragment_type.equalsIgnoreCase(Config.FRAGMENT_TYPE_SELF))
tag_name = "get_post_by_user";
following_id = fragment_extra;
else if (fragment_type.equalsIgnoreCase(Config.FRAGMENT_TYPE_TAG))
tag_name = "get_post_by_tags";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_post_view, container, false);
mContext = getActivity();
recyclerView = (RecyclerView) v.findViewById(R.id.recycler_post);
progressBar = (ProgressBar) v.findViewById(R.id.progressBar);
linear_search = (LinearLayout) v.findViewById(R.id.linear_search);
text_retry = (TextView) v.findViewById(R.id.text_retry);
linear_no_internet = (LinearLayout) v.findViewById(R.id.no_internet);
text_no_data = (TextView) v.findViewById(R.id.no_data_text);
if (tag_name.equalsIgnoreCase("get_post_by_famous"))
linear_search.setVisibility(View.VISIBLE);
linear_search.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Intent i = new Intent(mContext, SearchActivity.class);
startActivity(i);
);
else
linear_search.setVisibility(View.GONE);
swipeContainer = (SwipeRefreshLayout) v.findViewById(R.id.swipeContainer);
swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener()
@Override
public void onRefresh()
new PostTask(String.valueOf(1)).execute(Config.POST_URL);
);
final_list = new ArrayList<>();
new PostTask(String.valueOf(next_page_no)).execute(Config.POST_URL);
mLayoutManager = new LinearLayoutManager(mContext);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener()
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState)
mScrollState = newState;
Log.d("scrolling1233_onScrollStateChanged", String.valueOf(newState));
if (list != null)
if (newState == RecyclerView.SCROLL_STATE_IDLE && !list.isEmpty())
Log.d("scrolling1233_onScrollStateChanged", "onScrollStateChanged");
Log.d("scrolling1233_findFirstVisibleItemPosition",
String.valueOf(mLayoutManager.findFirstVisibleItemPosition()));
Log.d("scrolling1233_findLastVisibleItemPosition",
String.valueOf(mLayoutManager.findLastVisibleItemPosition()));
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
//super.onScrolled(recyclerView, dx, dy);
Log.d("scroll123_onScrolled", "onScrolled");
UtilMethods.LogMethod("scroll123_has_next_page", String.valueOf(has_next_page));
UtilMethods.LogMethod("scroll123_hasFooter", String.valueOf(hasFooter()));
if (has_next_page && !(hasFooter()))
LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
UtilMethods.LogMethod("scroll123_findLastCompletelyVisibleItemPosition",
String.valueOf(manager.findLastVisibleItemPosition()));
UtilMethods.LogMethod("scroll123_getItemCount",
String.valueOf(manager.getItemCount()));
if (manager.findLastVisibleItemPosition() == manager.getItemCount() - 2)
UtilMethods.LogMethod("scroll1235_next_page_no",
String.valueOf(next_page_no));
UtilMethods.LogMethod("scroll1235_has_nextPage",
String.valueOf(has_next_page));
UtilMethods.LogMethod("scroll123_findLastCompletelyVisibleItemPosition",
String.valueOf(manager.findLastVisibleItemPosition()));
new PostTask(String.valueOf(next_page_no)).execute(Config.POST_URL);
);
return v;
@Override
public void onResume()
super.onResume();
if (adapter != null)
adapter.notifyDataSetChanged();
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
// super.onActivityResult(requestCode, resultCode, data);
UtilMethods.LogMethod("kljlkc1234_", "djhjhkhkd");
if (resultCode == RESULT_OK)
if (requestCode == POST_COMMENT_REQUEST)
UtilMethods.LogMethod("kljlkc1234_", "djhjhkhkd");
@SuppressLint("StaticFieldLeak")
public class PostTask extends AsyncTask<String, Void, Integer>
int result = 0;
boolean jerror;
String jmsg;
private String page_no;
public PostTask(String page_no)
this.page_no = page_no;
@Override
protected void onPreExecute()
super.onPreExecute();
if (page_no.equalsIgnoreCase("1"))
swipeContainer.setRefreshing(true);
else
list.add(new Footer());
final_list = list;
recyclerView.getAdapter().notifyItemInserted(final_list.size());
@Override
protected Integer doInBackground(String... params)
RequestBody requestBody = null;
if (tag_name.equalsIgnoreCase("get_post_by_user"))
requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("tag", "get_post_by_user")
.addFormDataPart("self_user_id", Config.SelfId)
.addFormDataPart("to_see_user_id", following_id)
.addFormDataPart("page_no", page_no)
.build();
UtilMethods.LogMethod("text3434_tag", "get_post_by_user");
UtilMethods.LogMethod("text3434_self_user_id", Config.SelfId);
UtilMethods.LogMethod("text3434_to_see_user_id", following_id);
else if (tag_name.equalsIgnoreCase("get_posts_by_followers"))
requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("tag", "get_posts_by_followers")
.addFormDataPart("user_id", Config.SelfId)
.addFormDataPart("page_no", page_no)
.build();
else if (tag_name.equalsIgnoreCase("get_post_by_famous"))
requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("tag", "get_post_by_famous")
.addFormDataPart("self_user_id", Config.SelfId)
.addFormDataPart("page_no", page_no)
.build();
else if (tag_name.equalsIgnoreCase("get_post_by_tags"))
requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("tag", "get_post_by_tags")
.addFormDataPart("self_user_id", Config.SelfId)
.addFormDataPart("page_no", page_no)
.addFormDataPart("post_tag", fragment_extra)
.build();
Request request = new Request.Builder()
.url(params[0])
.post(requestBody)
.build();
OkHttpClient client = new OkHttpClient();
try
Response response = client.newCall(request).execute();
int status = response.networkResponse().code();
UtilMethods.LogMethod("response_status", String.valueOf(status));
if (status == 200)
String json_string = response.body().string();
UtilMethods.LogMethod("response_res", json_string);
parseJson(json_string);
result = 1;
else
result = 0;
catch (IOException e)
e.printStackTrace();
return result;
@Override
protected void onPostExecute(Integer integer)
super.onPostExecute(integer);
if (mContext != null)
swipeContainer.setRefreshing(false);
if (result == 1)
if (!jerror)
if (page_no.equalsIgnoreCase("1"))
recyclerView.setVisibility(View.VISIBLE);
linear_no_internet.setVisibility(View.GONE);
text_no_data.setVisibility(View.GONE);
final_list = list;
adapter = new PostViewAdapter(mContext, final_list, following_id);
// recyclerView.getItemAnimator().setChangeDuration(0);
recyclerView.setAdapter(adapter);
if (list != null)
if (!list.isEmpty())
// need to call this method from list view handler in order to have filled list
if (recyclerView != null)
// recyclerView.post(new Runnable()
// @Override
// public void run()
// if (mContext != null)
// mVideoVisibilityCalculator.onScrollStateIdle(
// mItemsPositionGetter,
// mLayoutManager.findFirstVisibleItemPosition(),
// mLayoutManager.findLastVisibleItemPosition());
//
//
//
// );
else
text_no_data.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
linear_no_internet.setVisibility(View.GONE);
if (tag_name.equalsIgnoreCase("get_post_by_user"))
text_no_data.setText("No Post Found.");
else if (tag_name.equalsIgnoreCase("get_posts_by_followers"))
text_no_data.setText("No Post Found.\n Follow more user to watch more media.");
else if (tag_name.equalsIgnoreCase("get_post_by_famous"))
text_no_data.setText("No Post Found.");
else if (tag_name.equalsIgnoreCase("get_post_by_tags"))
text_no_data.setText("No Post Found.");
else
int size = list.size();
list.remove(size - 1);
list.addAll(list1);
final_list = list;
// recyclerView.getAdapter().notifyItemRangeChanged(size - 1,
// list.size() - size);
recyclerView.getAdapter().notifyDataSetChanged();
else
Toast.makeText(mContext, jmsg, Toast.LENGTH_LONG).show();
else
if (page_no.equalsIgnoreCase("1"))
recyclerView.setVisibility(View.GONE);
linear_no_internet.setVisibility(View.VISIBLE);
text_no_data.setVisibility(View.GONE);
text_retry.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
linear_no_internet.setVisibility(View.GONE);
new PostTask(String.valueOf(1)).execute(Config.POST_URL);
);
else
Toast.makeText(mContext, "No internet connection", Toast.LENGTH_LONG).show();
public void parseJson(String s)
if (page_no.equalsIgnoreCase("1"))
list = new ArrayList<>();
else
list1 = new ArrayList<>();
try
JSONObject startingObject = new JSONObject(s);
jerror = startingObject.getBoolean("error");
if (!jerror)
page_no = startingObject.getString("page_number");
has_next_page = startingObject.getBoolean("has_next_page");
if (has_next_page)
next_page_no = startingObject.getInt("next_page_no");
JSONArray allDataArray = startingObject.getJSONArray("all_data");
if (allDataArray.length() > 0)
for (int i = 0; i < allDataArray.length(); i++)
PostViewModel model = new PostViewModel();
JSONObject object = allDataArray.getJSONObject(i);
JSONObject userObject = object.getJSONObject("user_data");
model.setUser_id(userObject.getString("user_id"));
model.setUser_name(userObject.getString("user_name"));
model.setUser_gcm_id(userObject.getString("user_gcm_id"));
model.setProfile_pic(userObject.getString("profile_pic"));
model.setTotal_posts(userObject.getString("total_posts"));
model.setTotal_followers(userObject.getString("total_followers"));
model.setTotal_followings(userObject.getString("total_followings"));
model.setStatus(userObject.getString("status"));
Object a = userObject.get("following");
if (a instanceof String)
model.setFollowing_type("Str");
model.setFollowing_string(userObject.getString("following"));
model.setFollowing(Boolean.parseBoolean(model.getFollowing_string()));
else
model.setFollowing_type("Bool");
model.setFollowing(userObject.getBoolean("following"));
model.setFollowing_string(String.valueOf(userObject.getBoolean("following")));
// model.setFollowing(userObject.getBoolean("following"));
model.setPoster_pic(userObject.getString("poster_pic"));
model.setShow_profile(userObject.getBoolean("show_profile"));
model.setBirth_date(userObject.getString("birth_date"));
model.setMobile_number(userObject.getString("mobile_number"));
model.setPrivacy_policy(userObject.getString("privacy_policy"));
model.setBlockedUser(userObject.getBoolean("is_blocked"));
JSONObject postObject = object.getJSONObject("post_data");
model.setPost_id(postObject.getString("post_id"));
model.setPost_message(postObject.getString("post_message"));
model.setPost_type(postObject.getString("post_type"));
model.setPost_path(postObject.getString("post_path"));
model.setPost_thumbnail(postObject.getString("post_thumbnail"));
model.setPost_tag(postObject.getString("post_tag"));
model.setCreated_at(postObject.getString("created_at"));
model.setTotal_likes(postObject.getString("total_likes"));
model.setTotal_comments(postObject.getString("total_comments"));
model.setPost_back_color_code(postObject.getString("post_back_color_code"));
model.setPost_back_image_id(postObject.getString("post_back_image_id"));
model.setIsSharingOn(postObject.getString("isSharingOn"));
model.setIsCommentsOn(postObject.getString("isCommentsOn"));
model.setPost_width(postObject.getString("post_width"));
model.setPost_height(postObject.getString("post_height"));
model.setIs_liked(postObject.getBoolean("is_liked"));
model.setLanguage(postObject.getString("post_language"));
model.setIs_notification_on(postObject.getBoolean("is_notification_on"));
if (model.getPost_tag().contains("18"))
UtilMethods.LogMethod("post738239_18888", "ifff");
if (MyApplication.getInstance().
getPrefManager().getEighteenPlus())
if (page_no.equalsIgnoreCase("1"))
list.add(model);
else
list1.add(model);
else
if (page_no.equalsIgnoreCase("1"))
list.add(model);
else
list1.add(model);
else
catch (JSONException e)
e.printStackTrace();
@Override
public void onPause()
super.onPause();
UtilMethods.LogMethod("recyclerView1234_music123", "pause");
if (MusicViewHolder.mp != null)
MusicViewHolder.mp.pause();
// UtilMethods.stopMediaPlayer();
@Override
public void onDetach()
super.onDetach();
UtilMethods.LogMethod("recyclerView1234_onDetach", "onDetach");
private boolean hasFooter()
if (list.size() > 0)
return list.get(list.size() - 1) instanceof Footer;
else
return true;
【讨论】:
以上是关于RecyclerView分页不起作用的主要内容,如果未能解决你的问题,请参考以下文章