-1

How can we achieve endless recyclerview inside co-ordinator layout? Below is my layout.

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ParentTownMaterialTheme.AppBarOverlay">

// Inside linear layout child views are there

        <LinearLayout
            android:id="@+id/linear_scroll_enter"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            app:layout_scrollFlags="scroll|enterAlways"/>

 </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/response_lv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/linear_scroll_enter"
        android:background="@android:color/white"
        android:clipToPadding="false"
        android:divider="@android:color/transparent"
        android:paddingBottom="6dp"
        android:paddingTop="6dp"
        android:scrollbars="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

Endless recyclerview working here but the in reverse order. such as :

item 10
item 9
item 8
item 7
item 6

----------
LOAD MORE
----------

item 5
item 4
item 3
item 2
item 1

It should be like :

 item 1
    item 2
    item 3
    item 4
    item 5

   -----------
    LOAD MORE
   -----------

    item 6
    item 7
    item 8
    item 9
    item 10

Here is java code :

response_lv.setHasFixedSize(false);
        final LinearLayoutManager mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, true);
        response_lv.setLayoutManager(mLayoutManager);
        response_lv.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
        response_lv.setItemAnimator(new DefaultItemAnimator());
        response_lv.setAdapter(profileFragmentRecyclerAdapter);

        response_lv.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                if (dy > 0) {
                    if ((mLayoutManager.getChildCount() + mLayoutManager.findFirstVisibleItemPosition()) >= mLayoutManager.getItemCount()) {
                        Log.d("TAG", "End of list");

                        totalItemCount = mLayoutManager.getItemCount();
                        lastVisibleItem = mLayoutManager.findLastVisibleItemPosition();

                        if (!isLoading && totalItemCount <= (lastVisibleItem + visibleThreshold)) {
                            isLoading = true;
                            current_page++;
                            setLoadingView();
                            new ProfileAsyncTask().execute();
                        }
                    }
                }
            }
        });

Any help appreciated. Thanks.

Mohanish Nerurkar
  • 441
  • 1
  • 4
  • 10

2 Answers2

0

An OnScrollListener can be set on a RecyclerView to receive messages when a scrolling event has occurred on that RecyclerView.

Here is a very good article how to achieve this ....link

Anudeep Samaiya
  • 1,700
  • 1
  • 27
  • 31
0

Currently, you're instructing the LayoutManager to reverse its layouts (that's what the 3rd/boolean parameter is for). Hence, the order is reversed.

You'll want to change:

final LinearLayoutManager mLayoutManager = 
    new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, true);

To:

final LinearLayoutManager mLayoutManager = 
    new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);

Which would be the same as just calling:

final LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
MH.
  • 44,118
  • 10
  • 98
  • 115