Last active
March 2, 2019 13:10
-
-
Save makorowy/5f8ec0b1b40fb816efb560ac5d9239bc to your computer and use it in GitHub Desktop.
Sample for article needs - How to create a compound view?
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 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