Skip to content

Instantly share code, notes, and snippets.

@Zhuinden
Last active November 27, 2019 20:33
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 Zhuinden/8b5ebd5121dc707753feb874099d6775 to your computer and use it in GitHub Desktop.
Save Zhuinden/8b5ebd5121dc707753feb874099d6775 to your computer and use it in GitHub Desktop.
Anemic Repository 5
class MyView(...): ... {
interface Listener {
fun onTextChanged(text: String)
fun onButtonPressed()
fun onCheckBoxTicked()
}
var listener: Listener? = null
// can make this a list if you want
override fun onFinishInflate() {
super.onFinishInflate()
button.onClick {
listener?.onButtonPressed()
}
editText.onTextChanged { text ->
listener?.onTextChanged(text)
}
checkBox.onCheckedChanged { checked ->
listener?.onCheckBoxTicked()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment