'Create a layout to include with a recyclerview and pass tools:listItem as argument
I´m trying to create a include to use as a default recyclerview to reuse in all my views, the code is this:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<import type="android.view.View" />
<variable
name="viewModel"
type="com.jsm.baserecycler.BaseRecyclerViewModel" />
<variable
name="listItemResource"
type="android.widget.LinearLayout" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:onRefreshListener="@{() -> viewModel.onRefresh()}"
app:refreshing="@{viewModel.isLoading}">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/elementsRV"
style="@style/RecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@{listItemResource}">
</androidx.recyclerview.widget.RecyclerView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<TextView
android:id="@+id/empty"
style="@style/TextViewNoItems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/default_recyclerview_emptyMessage"
android:visibility="@{viewModel.textEmptyVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
My goal is to pass a variable to the include which can configure the tools:listItem of the recycler inside the include
I tried to find which type I need to put in listItemResource to use the variable in
tools:listitem
I tried several types as Integer, Viewgroup... but always receive a error of type:
{"msg":"Cannot find a setter for \u003candroidx.recyclerview.widget.RecyclerView tools:listitem\u003e that accepts parameter type...
Which type I need to put on ????....
<variable
name="listItemResource"
type="????" />
...To do:
tools:listitem="@{listItemResource}
?
Update: As ADM pointed in comments and I researched, my approach is wrong, I guess the solution is to create a CompoundView that accepts that parameter
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
