Skip to content

Instantly share code, notes, and snippets.

@Draketheb4dass
Created July 28, 2021 14:36
Show Gist options
  • Select an option

  • Save Draketheb4dass/11815592c8499fecb1da4d61a7bd2e46 to your computer and use it in GitHub Desktop.

Select an option

Save Draketheb4dass/11815592c8499fecb1da4d61a7bd2e46 to your computer and use it in GitHub Desktop.

Revisions

  1. Draketheb4dass created this gist Jul 28, 2021.
    41 changes: 41 additions & 0 deletions CheckboxCustom.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    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
    }