Skip to content

Instantly share code, notes, and snippets.

@pramonow
Last active November 20, 2020 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pramonow/998fc3d0e1edac5b0492fe534ecbd52f to your computer and use it in GitHub Desktop.
Save pramonow/998fc3d0e1edac5b0492fe534ecbd52f to your computer and use it in GitHub Desktop.
//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