user4813855
user4813855

Reputation:

Loads more for second RecyclerView - android

I have below layout :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:clickable="true">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/signsRecycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

</RelativeLayout>

And below layout is items of above RecyclerView, in this layout I have another RecyclerView. How can I have loads more for second RecyclerView ?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:id="@+id/cardVisibleLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        card_view:cardElevation="2dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:orientation="horizontal">

            <com.joanzapata.iconify.widget.IconTextView
                android:id="@+id/itxtArrow"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@null"
                android:gravity="center"
                android:text="@string/fa_chevron_down"
                android:textColor="@color/orangePeel" />

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="right"
                android:layout_weight="5"
                android:gravity="right"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/txtCategoryName"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="right"
                    android:layout_marginRight="15dp"
                    android:layout_weight="5"
                    android:gravity="center_vertical" />
            </RelativeLayout>
        </LinearLayout>
    </android.support.v7.widget.CardView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/cardVisibleLayout">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rcyNested"
            android:layout_width="match_parent"
            android:layout_height="125dp" />
    </LinearLayout>

</RelativeLayout>

Upvotes: 0

Views: 67

Answers (1)

beeb
beeb

Reputation: 1615

This could help you:

How to load more data in RecyclerView when Scrolling on Android

So step by step:

  1. Add OnScrollListener to your RecyclerView to detect when you want to load more (for example load more if you are at last item)

  2. Create an interface for the more loading:

    public interface OnLoadMoreCallback { void onLoadMore(); }

  3. Implement the interface. Inside the onLoadMore() you can call for example a rest api. For this you can use AsyncTask.

  4. After you loaded new data you have to update the datamodels and notify your adapter that the data has been added.

Upvotes: 1

Related Questions