android-viewbinding

How using ViewBinding with an abstract base class

匆匆过客 提交于 2021-01-13 07:10:51
问题 I started using ViewBinding. After searching for some example or advice how to use ViewBinding with an abstract base class that should handle same logic on views expected to be present in every child's layout, I endet up posting this question here. Scenario: I have a base class public abstract class BaseFragment . There are multiple Fragments that extend this base class. These Fragments have common views that are handled from the base class implementation (with the "old" findViewById() ). For

How to use ViewBinding in a RecyclerView.Adapter?

北城余情 提交于 2020-12-29 02:43:55
问题 Can I use ViewBindings to replace findViewById in this typical RecyclerView.Adapter initialization code? I can't set a binding val in the object as the ViewHolders are different per cell. class CardListAdapter(private val cards: LiveData<List<Card>>) : RecyclerView.Adapter<CardListAdapter.CardViewHolder>() { class CardViewHolder(val cardView: View) : RecyclerView.ViewHolder(cardView) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CardViewHolder { val binding = CardBinding

How to use ViewBinding in a RecyclerView.Adapter?

强颜欢笑 提交于 2020-12-29 02:40:50
问题 Can I use ViewBindings to replace findViewById in this typical RecyclerView.Adapter initialization code? I can't set a binding val in the object as the ViewHolders are different per cell. class CardListAdapter(private val cards: LiveData<List<Card>>) : RecyclerView.Adapter<CardListAdapter.CardViewHolder>() { class CardViewHolder(val cardView: View) : RecyclerView.ViewHolder(cardView) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CardViewHolder { val binding = CardBinding