Last active
November 20, 2020 10:06
-
-
Save pramonow/998fc3d0e1edac5b0492fe534ecbd52f to your computer and use it in GitHub Desktop.
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
//Sample adapter with click interface | |
class DemoAdapter(val adapterOnClick: AdapterOnClick) : RecyclerView.Adapter<DemoAdapter.DemoVH> { | |
var itemList:MutableList<Any> = ArrayList() | |
override fun onBindViewHolder(demoVH: DemoVH, i: Int) { | |
demoVH.setItem(itemList.get(i)) | |
} | |
/* | |
implement other abstract method .. | |
*/ | |
inner class DemoVH : RecyclerView.ViewHolder { | |
//button to be binded with our click callback | |
var demoButton: Button | |
constructor(itemView: View) : super(itemView){ | |
demoButton = itemView.findViewById(R.id.button) | |
} | |
//we set our button click listener here | |
fun setItem(item: Any) { | |
demoButton.setOnClickListener {adapterOnClick.onClick(item)} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment