@@ -25,6 +25,8 @@ public class CounterView extends LinearLayout {
25
25
private String prefix = "" ;
26
26
27
27
private TextView txtCounter ;
28
+ private Button btnMinus ;
29
+ private Button btnPlus ;
28
30
private boolean isPlusEnabled ;
29
31
private boolean isMinusEnabled ;
30
32
private OnCountChangedListener listener ;
@@ -81,7 +83,7 @@ void init(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
81
83
ViewGroup .LayoutParams .WRAP_CONTENT , 1f ));
82
84
addView (txtCounter );
83
85
84
- Button btnMinus = new Button (context );
86
+ btnMinus = new Button (context );
85
87
btnMinus .setText ("-" );
86
88
btnMinus .setTextSize (18f );
87
89
LayoutParams layoutParams = new LinearLayout .LayoutParams (
@@ -91,7 +93,7 @@ void init(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
91
93
0 , context .getResources ().getDimensionPixelSize (R .dimen .margin_2dp ), 0 );
92
94
btnMinus .setLayoutParams (layoutParams );
93
95
btnMinus .setTextColor (ContextCompat .getColor (context , android .R .color .white ));
94
- btnMinus .setBackground (ContextCompat .getDrawable (context , R .drawable .bg_counter_left ));
96
+ btnMinus .setBackground (ContextCompat .getDrawable (context , R .drawable .bg_counter_left_state ));
95
97
btnMinus .setOnClickListener (v -> {
96
98
if (isMinusEnabled ){
97
99
--count ;
@@ -104,14 +106,14 @@ void init(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
104
106
});
105
107
addView (btnMinus );
106
108
107
- Button btnPlus = new Button (context );
109
+ btnPlus = new Button (context );
108
110
btnPlus .setText ("+" );
109
111
btnPlus .setTextSize (18f );
110
112
btnPlus .setLayoutParams (new LinearLayout .LayoutParams (
111
113
context .getResources ().getDimensionPixelSize (R .dimen .btn_counter_width ),
112
114
ViewGroup .LayoutParams .MATCH_PARENT ));
113
115
btnPlus .setTextColor (ContextCompat .getColor (context , android .R .color .white ));
114
- btnPlus .setBackground (ContextCompat .getDrawable (context , R .drawable .bg_counter_right ));
116
+ btnPlus .setBackground (ContextCompat .getDrawable (context , R .drawable .bg_counter_right_state ));
115
117
btnPlus .setOnClickListener (v -> {
116
118
if (isPlusEnabled ){
117
119
++count ;
@@ -141,6 +143,16 @@ private void disableButtonsIfNeeded() {
141
143
} else {
142
144
isMinusEnabled = false ;
143
145
}
146
+ setDisabilityLeftCounterButton ();
147
+ setDisabilityRightCounterButton ();
148
+ }
149
+
150
+ private void setDisabilityLeftCounterButton () {
151
+ btnMinus .setEnabled (isMinusEnabled );
152
+ }
153
+
154
+ private void setDisabilityRightCounterButton () {
155
+ btnPlus .setEnabled (isPlusEnabled );
144
156
}
145
157
146
158
private void redrawCounter (int count ) {
0 commit comments