epic
epic

Reputation: 1443

How to place TextView at the end of recyclerView list

I would like to add a simple TextView at the end of a recyclerView list to help the user in case he didn't find the item he was looking for. But, like everything on android, nothing is simple and the documentation are worthless.

Please note i do not want to achieve this via Recyclerview adapter manipulation such as suggested here:

How to add a button at the end of RecyclerView?

I tried many options and reading on google. Following was my last attempt

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.circularreveal.coordinatorlayout.CircularRevealCoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    tools:context=".collaborate.CollaborateActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent">
    <include
        android:id="@+id/collaborate_toolbar"
        layout="@layout/toolbar" />
    </com.google.android.material.appbar.AppBarLayout>


    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/collaborate_rv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="80dp"
                android:clipToPadding="false"
                android:useDefaultMargins="true"
                android:alignmentMode="alignBounds"
                android:columnOrderPreserved="false"
                tools:listitem="@layout/list_collaborate" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Didn't find what you were looking for? try...."/>

            </LinearLayout>

        </androidx.core.widget.NestedScrollView>


    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/collaborate_fb_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="16dp"
        android:layout_marginEnd="8dp"
        android:src="@drawable/check" />

</com.google.android.material.circularreveal.coordinatorlayout.CircularRevealCoordinatorLayout>

Upvotes: 1

Views: 1496

Answers (2)

Drioueche Mohammed
Drioueche Mohammed

Reputation: 560

For me,

  1. I put the view that I want to show at the end of the recycler view at the bottom of my adapter layout.

  2. And then, in my bind method in the adapter I add the following line:

    binding.myBottomView.setVisibility(position == (adapterList.size() - 1) ? View.VISIBLE : View.GONE);

Upvotes: 1

shivang
shivang

Reputation: 326

Best way is to add another view type to your Recycler View adapter and display that particular layout(in your case the text view) when the view type matches.

Upvotes: 0

Related Questions