I'm hoping someone can show me the ropes of hopefully ViewPager2, but I'm basically in need of making a viewpager where I can swipe between different images.
I will have a category, let's call it Category A. Category A can have multiple items in it, each with a picture and small description.
I would love to do a Header out of Category A, then below that I want to be able to swipe through these items, while the description below the viewpager of items, updates to match the corresponding item shown.
This is also done within a recyclerview, since I can have multiple categories.
Right now I'm trying something like
<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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/category"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Hosomaki" />
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/category" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
and then in my RecyclerAdapter, I was thinking of being able to do something like this
private class CategoryItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(item: CategoryItemViewModel) = with(itemView) {
itemView.category.text = item.category.title
// Something here is what I'm missing
val adapter = ViewPagerAdapter(itemView.context, item.items)
itemView.viewPager.adapter = adapter
}
}
Hopefully my question makes sense.. :D