@@ -28,6 +28,7 @@ if (OS_ANDROID) {
28
28
$ . segCtrlButtonContainer . height = Ti . UI . FILL ;
29
29
30
30
var callback = function ( ) { } ; // empty function as placeholder
31
+ var selectedIndex = 0 ; // Stores the current selected index
31
32
32
33
var buttons = [ ] ;
33
34
exports . init = function ( labels , cb ) {
@@ -138,6 +139,10 @@ exports.init = function (labels, cb) {
138
139
}
139
140
}
140
141
} ) ;
142
+
143
+ // Save current value
144
+ selectedIndex = clickedButton ;
145
+
141
146
callback ( {
142
147
index : clickedButton ,
143
148
source : {
@@ -161,14 +166,18 @@ function _unhighlight(btn) {
161
166
}
162
167
}
163
168
169
+ // Is an alias function
164
170
exports . select = function ( num ) {
165
- var btnNumber = parseInt ( num ) || 0 ;
166
- _highlight ( buttons [ btnNumber ] ) ;
171
+ exports . setIndex ( num ) ;
172
+ } ;
173
+ exports . getIndex = function ( ) {
174
+ return selectedIndex ;
167
175
} ;
168
176
exports . setIndex = function ( num ) {
169
- var btnNumber = parseInt ( num ) || 0 ;
170
- exports . deselectAll ( ) ;
171
- _highlight ( buttons [ btnNumber ] ) ;
177
+ var btnNumber = parseInt ( num ) || 0 ;
178
+ exports . deselectAll ( ) ;
179
+ _highlight ( buttons [ btnNumber ] ) ;
180
+ selectedIndex = num ;
172
181
} ;
173
182
exports . deselect = function ( num ) {
174
183
var btnNumber = parseInt ( num ) || 0 ;
@@ -238,4 +247,4 @@ exports.enableAllButtons = function () {
238
247
function onThreeDPDevice ( ) {
239
248
//if we are on a 3DP device (6+ or 6s+) we need to slightly adjust the button width
240
249
return OS_IOS && parseInt ( Ti . Platform . displayCaps . logicalDensityFactor ) === 3 ;
241
- }
250
+ }
0 commit comments