Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When new items in rv added, its move to the top. Why?

Java
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();
    }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900