0

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>
epic
  • 1,333
  • 1
  • 13
  • 27
  • The question you linked is exactly the solution you need. What's wrong with it? – Nicolas May 30 '20 at 14:49
  • First, such manipulation can't be the best practice to do something as basic as that. I just can't accept it. Second, i am using FirestoreRecyclerAdapter which cannot implement that. Why does the NestedScrollView not working? Does it not supposed to do that? Am i using it wrong? – epic May 30 '20 at 14:53
  • Agree with @Nicolas. Here is almost the exact implementation from the question you linked: https://stackoverflow.com/a/38691600/7210237 – Jenea Vranceanu May 30 '20 at 14:54
  • 2
    "such manipulation can't be the best practice to do something as basic as that. I just can't accept it." Welcome to android development :) If you use NestedScrollView, your RecyclerView won't recycle anything because the RecyclerView height isn't fixed. I don't know about FirestoreRecyclerAdapter so I can't really help you with that. – Nicolas May 30 '20 at 14:57
  • 1
    @Ran, here is an example, Kotlin-based, and official: https://codelabs.developers.google.com/codelabs/kotlin-android-training-headers/#0 A little bit too long, but the solution is almost the same. In Android there is no `addFooter` function to simply snap a view under the list. – Jenea Vranceanu May 30 '20 at 14:58
  • On Whatsapp "Group info" they achieve this quite elegantly, how do they do that? They can't be using same solution. right? – epic May 30 '20 at 15:00
  • @Ran Another solution is to use [MergeAdapter](https://developer.android.com/reference/androidx/recyclerview/widget/MergeAdapter). – Hussein El Feky May 30 '20 at 15:01

2 Answers2

1

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);

0

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.

shivang
  • 266
  • 3
  • 7