This recyclerview is a simplified version of the recyclerview that is often used to create lists, which only requires a few lines of code that are already prepared and can be customized.
For Example:
The first step is to create a view of the recyclerview using an xml file
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="wrap_content"android:paddingHorizontal="16dp"android:paddingTop="16dp"android:background="?selectableItemBackground"xmlns:tools="http://schemas.android.com/tools"> <TextViewandroid:id="@+id/tv_title"android:layout_width="match_parent"android:layout_height="wrap_content"android:textColor="@color/black"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent"tools:text="This is a text" /> <com.google.android.material.divider.MaterialDividerandroid:layout_width="match_parent"android:layout_height="wrap_content"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toBottomOf="@+id/tv_title"android:layout_marginTop="12dp"/></androidx.constraintlayout.widget.ConstraintLayout>
Then, you can create an class of recyclerview and extend to BaseAsyncRecyclerAdapter. For example:
After the adapter is successfully created, you can call the adapter on the Activity/Fragment to enter data according to your needs, to use it you can use kotlin lazy. For example:
// Activity/Fragmentprivateval asyncAdapter: TestBaseAsyncRecyclerAdapterbylazy {TestBaseAsyncRecyclerAdapter( context =this, onItemClicked = {} )}// and insert data overridefuninitObservers() { asyncAdapter.setData = Constant.dataList()}