File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed
java/com/huynn109/increase_decrease_button_demo
lib/src/main/java/com/huynn109 Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ class MainActivity : AppCompatActivity() {
1111 super .onCreate(savedInstanceState)
1212 setContentView(R .layout.activity_main)
1313 val btn = findViewById<IncreaseDecreaseButton >(R .id.inDeButton)
14+ btn.initNumber(3 )
15+ btn.setMaxNumber(15 )
16+ btn.setMinNumber(2 )
1417 btn.onChangeListener { number, isIncrease ->
1518 Toast .makeText(this .applicationContext, " $number " , Toast .LENGTH_SHORT ).show()
1619 Timber .d(" onCreate: ${btn.getCurrentNumber()} " )
Original file line number Diff line number Diff line change 1111 app : activeIconColor =" @color/increase_decrease_lib_active"
1212 app : minNumber =" 1"
1313 app : maxNumber =" 10"
14- app : initNumber =" 2"
1514 android : layout_width =" wrap_content"
1615 android : layout_height =" wrap_content"
1716 app : layout_constraintBottom_toBottomOf =" parent"
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import kotlin.properties.Delegates
1111
1212
1313class IncreaseDecreaseButton @JvmOverloads constructor(
14- context : Context , private val attrs : AttributeSet ? = null
14+ context : Context , private val attrs : AttributeSet ? = null ,
1515) : LinearLayout(context, attrs) {
1616
1717 private var iconSize: Float = 0.0f
@@ -88,6 +88,23 @@ class IncreaseDecreaseButton @JvmOverloads constructor(
8888 }
8989 }
9090
91+ fun setMaxNumber (maxNumber : Int ) {
92+ if (maxNumber <= minNumber)
93+ this .maxNumber = minNumber
94+ else this .maxNumber = maxNumber
95+ }
96+
97+ fun setMinNumber (minNumber : Int ) {
98+ if (maxNumber <= minNumber)
99+ this .minNumber = maxNumber
100+ else this .minNumber = minNumber
101+ }
102+
103+ fun initNumber (initNumber : Int ) {
104+ this .initNumber = initNumber
105+ bindViewRes()
106+ }
107+
91108 private fun initViewId () {
92109 increaseButton = findViewById(R .id.increaseButton)
93110 decreaseButton = findViewById(R .id.decreaseButton)
You can’t perform that action at this time.
0 commit comments