Skip to content

Instantly share code, notes, and snippets.

@pramonow
Created November 20, 2020 10:09
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/bd1b50ef9fbc69943573001fd5e9fddd to your computer and use it in GitHub Desktop.
Save pramonow/bd1b50ef9fbc69943573001fd5e9fddd to your computer and use it in GitHub Desktop.
//Adapter having lambda function inside the constructor
class DemoAdapter(val adapterOnClick : (Any) -> Unit): RecyclerView.Adapter<DemoAdapter.DemoVH>(){
var itemList:MutableList<Any> = ArrayList()
override fun onBindViewHolder(demoVH: DemoVH, i: Int) {
demoVH.setItem(itemList.get(i))
}
/*
other abstract method implementation
*/
inner class DemoVH : RecyclerView.ViewHolder {
var demoButton: Button
constructor(itemView: View) : super(itemView){
demoButton = itemView.findViewById(R.id.button)
}
//set our click method here
fun setItem(item: Any) {
demoButton.setOnClickListener { adapterOnClick(item) }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment