Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

convert myAdapter synthetic to viewbinding

i’m confused, how can i update my adapter views from synthetic to viewbinding!
here is my code, how define viewbinding to viewHolder?

class PlayersListAdapter(
    var items: ArrayList<MatchPlayer>
) :
    RecyclerView.Adapter<RecyclerView.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {

        val inflate: View =
            LayoutInflater.from(parent.context)
                .inflate(R.layout.item_team_player, parent, false)

        return MatchSubstitutionHolder(inflate)
    }


    override fun onBindViewHolder(viewHolder: RecyclerView.ViewHolder, position: Int) {

        viewHolder.itemView.lblPlayerName.text = "name"

    }

    class MatchSubstitutionHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        var view = itemView
    }

    override fun getItemCount(): Int {
        return items.size

    }

}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

it’s so easy like define viewbinding in fragment or activity

class PlayersListAdapter(
    var items: ArrayList<MatchPlayer>
) :
    RecyclerView.Adapter<TeamPlayersListAdapter.MatchSubstitutionHolder>() {

  

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MatchSubstitutionHolder {

        val binding= ItemTeamPlayerBinding.inflate(LayoutInflater.from(parent.context),parent,false)

        return MatchSubstitutionHolder(binding)
    }


    override fun onBindViewHolder(viewHolder: MatchSubstitutionHolder, position: Int) {

        viewHolder.binding.lblPlayerName.text = "name"

    }

    class MatchSubstitutionHolder(val binding: ItemTeamPlayerBinding) : RecyclerView.ViewHolder(binding.root)


    override fun getItemCount(): Int {
        return items.size

    }}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading