Created
November 20, 2020 10:09
-
-
Save pramonow/bd1b50ef9fbc69943573001fd5e9fddd 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
//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