I have created a FloatingActionButton to switch the view between `gridView` and `listView` of the `recyclerView` in an `fragment`. I just wanted to make sure that the FloatingActionButton works correctly and So I just added a `toast. However, the toast doesn't show up when I hit the button.

`fragment_dashboard.xml`

```
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:background="@color/colorOffWhite"
    tools:context=".ui.fragments.DashboardFragment">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_dashboard_items"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fb_dashboard"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="10dp"
        android:layout_marginBottom="60dp"
        android:backgroundTint="@color/colorAccent"
        android:clickable="true"
        android:focusable="true"
        android:src="@drawable/ic_grid_list_view"
        app:layout_anchorGravity="bottom|right|end"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <TextView
        android:id="@+id/tv_no_dashboard_items_found"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:text="@string/no_dashboard_item_found"
        android:textAlignment="center"
        android:textSize="@dimen/no_data_found_textSize"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

```

`DashboardFragment.kt`

```
    class DashboardFragment : BaseFragment() {

    private var binding: FragmentDashboardBinding? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setHasOptionsMenu(true)

    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding?.fbDashboard?.setOnClickListener { view ->

            Toast.makeText(requireContext(), "You clicked FA Button", Toast.LENGTH_LONG).show()

        }
        val root = inflater.inflate(R.layout.fragment_dashboard, container, false)

        return root

    }
}

```

I get the following error when I use the code in the first answer.
[![I get the following error when I use the code in the first answer](https://i.stack.imgur.com/XeaWA.png)](https://i.stack.imgur.com/XeaWA.png)