WIP Recycleradapter

This commit is contained in:
Daniele Verducci (ZenPenguin) 2021-08-31 08:55:10 +02:00
parent 4307e1c84a
commit 25c8cb8a5d
3 changed files with 8 additions and 13 deletions

View File

@ -2,25 +2,20 @@ package it.danieleverducci.subitobeers
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import it.danieleverducci.subitobeers.placeholder.PlaceholderContent.PlaceholderItem import it.danieleverducci.subitobeers.databinding.FragmentBeersListitemBinding
import it.danieleverducci.subitobeers.databinding.FragmentBeersBinding import it.danieleverducci.subitobeers.entities.Beer
/**
* [RecyclerView.Adapter] that can display a [PlaceholderItem].
* TODO: Replace the implementation with code for your data type.
*/
class BeerRecyclerAdapter( class BeerRecyclerAdapter(
private val values: List<PlaceholderItem> private val values: List<Beer>
) : RecyclerView.Adapter<BeerRecyclerAdapter.ViewHolder>() { ) : RecyclerView.Adapter<BeerRecyclerAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder( return ViewHolder(
FragmentBeersBinding.inflate( FragmentBeersListitemBinding.inflate(
LayoutInflater.from(parent.context), LayoutInflater.from(parent.context),
parent, parent,
false false
@ -31,13 +26,13 @@ class BeerRecyclerAdapter(
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = values[position] val item = values[position]
holder.idView.text = item.id holder.idView.text = item.name
holder.contentView.text = item.content holder.contentView.text = item.tagline
} }
override fun getItemCount(): Int = values.size override fun getItemCount(): Int = values.size
inner class ViewHolder(binding: FragmentBeersBinding) : RecyclerView.ViewHolder(binding.root) { inner class ViewHolder(binding: FragmentBeersListitemBinding) : RecyclerView.ViewHolder(binding.root) {
val idView: TextView = binding.itemNumber val idView: TextView = binding.itemNumber
val contentView: TextView = binding.content val contentView: TextView = binding.content

View File

@ -10,4 +10,4 @@
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager" app:layoutManager="LinearLayoutManager"
tools:context=".BeersFragment" tools:context=".BeersFragment"
tools:listitem="@layout/fragment_beers" /> tools:listitem="@layout/fragment_beers_listitem" />