Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tools:listitem for custom view extending RecyclerView

I try to use tools:listitem to show correctly styled sample-data on a RecyclerView. This works fine when using the original view.

But when extending RecyclerView to create my own custom view to add some functionality it just shows an empty space in the layout-preview in Android Studio.

How can I use all of the layout-preview stuff of a View when extending it?

My View looks like this:

class TestRecyclerView(
    context: Context,
    attrs: AttributeSet? = null,
    defStyle: Int
) : RecyclerView(context, attrs, defStyle) { }

Any ideas?

like image 611
hardysim Avatar asked Nov 08 '18 09:11

hardysim


1 Answers

<com.test.my.TestRecyclerView
        android:id="@+id/your_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        tools:listitem="@layout/your_item"/>

Don't forget to put a app:layoutManager attribute in your custom RecyclerView!

app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"

enter image description here

like image 54
Vince Avatar answered Nov 12 '22 05:11

Vince