Created
May 6, 2021 20:33
-
-
Save wiztensai/cebe2cbd40405aacd3a29982916f1af3 to your computer and use it in GitHub Desktop.
Recyclerview adapter with viewBinding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/recyclerView" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RvHome(val data:MutableList<ModelClass>): RecyclerView.Adapter<RvHome.ViewHolder>() { | |
lateinit var bind:ItemClassTodayBinding | |
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
fun dataBind(d:ModelClass) { | |
bind.tvTitle.setText(d.title) | |
bind.tvSubtitle.setText(d.subtitle) | |
} | |
} | |
override fun getItemCount(): Int { | |
return data.size | |
} | |
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
holder.dataBind(data[position]) | |
} | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | |
bind = ItemClassTodayBinding.inflate(LayoutInflater.from(parent.context)) | |
return ViewHolder(bind.root) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment