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 android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import it.danieleverducci.subitobeers.placeholder.PlaceholderContent.PlaceholderItem
import it.danieleverducci.subitobeers.databinding.FragmentBeersBinding
import it.danieleverducci.subitobeers.databinding.FragmentBeersListitemBinding
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(
private val values: List<PlaceholderItem>
private val values: List<Beer>
) : RecyclerView.Adapter<BeerRecyclerAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
FragmentBeersBinding.inflate(
FragmentBeersListitemBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
@ -31,13 +26,13 @@ class BeerRecyclerAdapter(
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = values[position]
holder.idView.text = item.id
holder.contentView.text = item.content
holder.idView.text = item.name
holder.contentView.text = item.tagline
}
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 contentView: TextView = binding.content

View File

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