Skip to content

Instantly share code, notes, and snippets.

@makorowy
makorowy / activity_main.xml
Last active March 2, 2019 13:11
Sample for article needs - How to create a compound view?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
@makorowy
makorowy / MainActivity.kt
Last active March 2, 2019 13:11
Sample for article needs - How to create a compound view?
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
consent1.setOnCheckedChangeListener { _, _ -> validateConsents() }
consent2.setOnCheckedChangeListener { _, _ -> validateConsents() }
}
@makorowy
makorowy / activity_main.xml
Last active March 2, 2019 13:11
Sample for article needs - How to create a compound view?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<include
@makorowy
makorowy / consents_view.xml
Last active March 2, 2019 13:11
Sample for article needs - How to create a compound view?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/consentsTitle"
android:layout_width="wrap_content"
@makorowy
makorowy / ConsentsView.kt
Last active March 2, 2019 13:10
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() }
@makorowy
makorowy / MainActivity.kt
Last active March 2, 2019 12:53
Sample for article needs - How to create a compound view?
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
consentsView.onConsentsCheckedChangeListener = { allConsentsChecked ->
confirmButton.isEnabled = allConsentsChecked
}
}
@makorowy
makorowy / activity_main.xml
Created March 2, 2019 12:52
Sample for article needs - How to create a compound view?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<com.makor.compoundviewexample.ConsentsView
@makorowy
makorowy / consents_view.xml
Created March 2, 2019 13:21
Sample for article needs - How to create a compound view?
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:parentTag="android.widget.LinearLayout"
tools:orientation="vertical"
tools:gravity="center">
<TextView
@makorowy
makorowy / attrs.xml
Created March 2, 2019 13:54
Sample for article needs - How to create a compound view?
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="ConsentsView">
<attr name="separatorVisibility" format="boolean"/>
</declare-styleable>
</resources>
@makorowy
makorowy / ConsentsView.kt
Created March 2, 2019 13:59
Sample for article needs - How to create a compound view?
package com.makor.compoundviewexample
import android.content.Context
import android.util.AttributeSet
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import kotlinx.android.synthetic.main.consents_view.view.*