5 июля, 2022

WeatherApp #9: RecyclerView Adapter – Part 1

WeatherAdapter import android.view.Viewimport androidx.recyclerview.widget.ListAdapterimport androidx.recyclerview.widget.RecyclerViewimport com.meter_alc_rgb.weatherappcursey.databinding.ListItemBindingclass WeatherAdapter : ListAdapter<WeatherModel, WeatherAdapter.Holder>() { class Holder(view: View) : RecyclerView.ViewHolder(view){ val binding = ListItemBinding.bind(view) fun bind(item: WeatherModel) = with(binding){ tvDate.text = item.time tvCondition.text = item.condition tvTemp.text = item.currentTemp } }} fragment_hours.xml <?xml version=”1.0″ encoding=”utf-8″?><androidx.constraintlayout.widget.ConstraintLayout 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” android:layout_width=”match_parent” android:layout_height=”match_parent” tools:context=”.fragments.HoursFragment”> <androidx.recyclerview.widget.RecyclerView android:id=”@+id/rcView” android:layout_width=”match_parent” android:layout_height=”match_parent” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintHorizontal_bias=”0.0″ app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toTopOf=”parent” app:layout_constraintVertical_bias=”1.0″ /> <TextView android:id=”@+id/tvEmpty” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:gravity=”center” android:text=”Empty” android:visibility=”gone” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toTopOf=”parent” /></androidx.constraintlayout.widget.ConstraintLayout>