Created
May 18, 2018 03:44
-
-
Save chipcerio/1cba79749402207ca7627bfc5b14d8ca to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class MainActivity : Activity, Adapter.OnCellClickListener { | |
override fun onCreate() { | |
recyclerView.setAdapter(Adapter(this)) // this refers to OnCellClickListener | |
} | |
override fun onCellClick(item: ChattrItem) { | |
// hoooray i have access to ChattrItem!!! | |
} | |
} |
This file contains hidden or 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
class Adapter(private val listener: OnCellClickListener) { | |
override fun onCreateViewHolder() {...} | |
override fun onBindViewHolder() {...} | |
override fun getItemCount() {...} | |
interface OnCellClickListener { | |
fun onCellClick(item: ChattrItem) | |
} | |
inner class CustomViewHolder(view: View) { | |
fun bind(item: ChattrItem) { | |
view.setOnClickListener { | |
listener.onCellClick(item) // pass ChattrItem to this interface | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment