Skip to content

Instantly share code, notes, and snippets.

@Draketheb4dass
Created July 28, 2021 14:36
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 Draketheb4dass/11815592c8499fecb1da4d61a7bd2e46 to your computer and use it in GitHub Desktop.
Save Draketheb4dass/11815592c8499fecb1da4d61a7bd2e46 to your computer and use it in GitHub Desktop.
package com.jephtecolin.kwii.ui.custom
import android.content.Context
import android.util.AttributeSet
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.appcompat.widget.AppCompatCheckBox
import androidx.appcompat.widget.AppCompatTextView
import com.jephtecolin.kwii.R
class CheckboxCustom @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs) {
private val root: ViewGroup
private val tvTitle: AppCompatTextView
private val tvPrice: AppCompatTextView
private val checkbox: AppCompatCheckBox
init {
inflate(context, R.layout.checkbox_custom, this)
root = findViewById(R.id.root)
tvTitle = findViewById(R.id.tvTitle)
tvPrice = findViewById(R.id.tvPrice)
checkbox = findViewById(R.id.checkbox)
checkbox.isChecked
root.setOnClickListener {
checkbox.toggle()
this.callOnClick()
}
}
fun setTitle(title: String) {
tvTitle.text = title
}
fun setPrice(price: String) {
tvPrice.text = price
}
fun isChecked(): Boolean = checkbox.isChecked
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment