From 25c8cb8a5d939d7dcf9eca1333867b8a18c52601 Mon Sep 17 00:00:00 2001 From: "Daniele Verducci (ZenPenguin)" Date: Tue, 31 Aug 2021 08:55:10 +0200 Subject: [PATCH] WIP Recycleradapter --- .../subitobeers/BeerRecyclerAdapter.kt | 19 +++++++------------ .../main/res/layout/fragment_beers_list.xml | 2 +- ..._beers.xml => fragment_beers_listitem.xml} | 0 3 files changed, 8 insertions(+), 13 deletions(-) rename app/src/main/res/layout/{fragment_beers.xml => fragment_beers_listitem.xml} (100%) diff --git a/app/src/main/java/it/danieleverducci/subitobeers/BeerRecyclerAdapter.kt b/app/src/main/java/it/danieleverducci/subitobeers/BeerRecyclerAdapter.kt index d25d4a7..0d7e230 100644 --- a/app/src/main/java/it/danieleverducci/subitobeers/BeerRecyclerAdapter.kt +++ b/app/src/main/java/it/danieleverducci/subitobeers/BeerRecyclerAdapter.kt @@ -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 + private val values: List ) : RecyclerView.Adapter() { 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 diff --git a/app/src/main/res/layout/fragment_beers_list.xml b/app/src/main/res/layout/fragment_beers_list.xml index 3b28a1a..8971108 100644 --- a/app/src/main/res/layout/fragment_beers_list.xml +++ b/app/src/main/res/layout/fragment_beers_list.xml @@ -10,4 +10,4 @@ android:layout_marginRight="16dp" app:layoutManager="LinearLayoutManager" tools:context=".BeersFragment" - tools:listitem="@layout/fragment_beers" /> \ No newline at end of file + tools:listitem="@layout/fragment_beers_listitem" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_beers.xml b/app/src/main/res/layout/fragment_beers_listitem.xml similarity index 100% rename from app/src/main/res/layout/fragment_beers.xml rename to app/src/main/res/layout/fragment_beers_listitem.xml