mLinearLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView = (RecyclerView)rootView.findViewById(R.id.recycleralda);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mSwipeRefreshLayout = (SwipeRefreshLayout)rootView.findViewById(R.id.swipeRefreshLayout);
mSwipeRefreshLayout.setRefreshing(false);
mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
visibleItemCount = mRecyclerView.getChildCount();
totalItemCount = mLinearLayoutManager.getItemCount();
firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();
if (loading) {
if (totalItemCount > previousTotal) {
loading = false;
previousTotal = totalItemCount;
}
}
if (!loading && (totalItemCount - visibleItemCount)
<= (firstVisibleItem + visibleThreshold)) {
currentPage++;
populateData();
// End has been reached
Log.i("...", "end called");
// Do something
loading = true;
}
}
});
public void init() {
mRecyclerviewAdapter = new RecyclerViewAdapter(lNews,getActivity());
mRecyclerView.setAdapter(mRecyclerviewAdapter);
mRecyclerviewAdapter.notifyDataSetChanged();
}
public RecyclerView.OnScrollListener onScroll = new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
...
More();
}
};
public void More(){
new UpdateDataFromMongoDb().execute(CurrentSection);
}
protected class UpdateDataFromMongoDb extends AsyncTask{
protected void onPreExecute() {
super.onPreExecute();
swipeLayout.setRefreshing(true);
}
protected doInBackground() {
... Добавление к существующему списку
ListOfNews.add(cnews);
}
protected void onPostExecute() {
swipeLayout.setRefreshing(false);
adapter.notifyDataSetChanged();
}
}