Skip to content

Instantly share code, notes, and snippets.

@makorowy
Last active March 2, 2019 13:10
Show Gist options
  • Select an option

  • Save makorowy/5f8ec0b1b40fb816efb560ac5d9239bc to your computer and use it in GitHub Desktop.

Select an option

Save makorowy/5f8ec0b1b40fb816efb560ac5d9239bc to your computer and use it in GitHub Desktop.
Sample for article needs - How to create a compound view?
class ConsentsView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {
var onConsentsCheckedChangeListener: (allConsentsChecked: Boolean) -> Unit = {}
init {
LayoutInflater.from(context).inflate(R.layout.consents_view, this, true)
consent1.setOnCheckedChangeListener { _, _ -> validateConsents() }
consent2.setOnCheckedChangeListener { _, _ -> validateConsents() }
}
private fun validateConsents() {
onConsentsCheckedChangeListener.invoke(consent1.isChecked && consent2.isChecked)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment