Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to binding a RecycleView.Adataper #14

Open
a316375 opened this issue Oct 16, 2018 · 1 comment
Open

How to binding a RecycleView.Adataper #14

a316375 opened this issue Oct 16, 2018 · 1 comment

Comments

@a316375
Copy link

a316375 commented Oct 16, 2018

How to binding a RecycleView.Adataper
How to use in RecycleView

@kimkevin
Copy link

kimkevin commented Nov 27, 2018

@a316375

In my case, I created a BindingViewHolder which has ViewDataBinding of generic T type instead of ViewHolder classes such as HeaderViewHolder, ItemViewHolder and etc.

class BindingViewHolder<T: ViewDataBinding> 
    constructor(val binding: T): RecyclerView.ViewHolder(binding.root)

You can create BindingViewHolder on onCreateViewHolder method.

override fun onCreateViewHolder(parent: ViewGroup, position: Int): 
    BindingViewHolder<ViewDataBinding> {
    return BindingViewHolder(ItemScheduleBinding.inflate(
        LayoutInflater.from(parent.context), parent, false))
}

Set data to Binding class.

override fun onBindViewHolder(
    viewHolder: BindingViewHolder<ViewDataBinding>, position: Int) {
    val binding = viewHolder.binding as ItemScheduleBinding
    binding.schedule = items.get(position)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants