How to set "id" in newSegmentedControl?

How can I set “id” in newSegmentedControl?

I’ve tried the following, but target.id is always nil.

        local function onSegmentPress( event )             local target = event.target                  print( "Segment Label is:", target.segmentLabel )             print( "Segment Number is:", target.segmentNumber )             print( "id:", target.id )         end                  local segmentedControl = widget.newSegmentedControl         {             id = "myID",             left = 0,             top = b.y - 13,             segmentWidth = 60,             segments = s,             defaultSegment = 1,             onPress = onSegmentPress        }  

Not sure but try event.target._view.id.

it’s not it 

attempt to index field '\_view' (a nil value)  

Note that this is likely to change in future builds but currently you can get it like this:

 local function onSegmentPress( event ) local target = event.target print( "Segment Label is:", target.segmentLabel ) print( "Segment Number is:", target.segmentNumber ) print( "id:", target[1].id ) end

Actually hold on. Looking at the source for segmented control I’m sure this is a bug. What I posted earlier will only work if the segmented control is the first item inserted in the group it’s in or the stage group (no group). If it’s not first it wont work.

You should report this as a bug.

didn’t work either. got a completely wrong id name .

As I mentioned it’s a bug. Why it’s not working is because instead of the segmented control being returned as event.target it actually returns the parent of the segmented control which in the case of your sample is the stage group. And as you probably insert something else before the segmented control its giving the wrong id.

Not sure but try event.target._view.id.

it’s not it 

attempt to index field '\_view' (a nil value)  

Note that this is likely to change in future builds but currently you can get it like this:

 local function onSegmentPress( event ) local target = event.target print( "Segment Label is:", target.segmentLabel ) print( "Segment Number is:", target.segmentNumber ) print( "id:", target[1].id ) end

Actually hold on. Looking at the source for segmented control I’m sure this is a bug. What I posted earlier will only work if the segmented control is the first item inserted in the group it’s in or the stage group (no group). If it’s not first it wont work.

You should report this as a bug.

didn’t work either. got a completely wrong id name .

As I mentioned it’s a bug. Why it’s not working is because instead of the segmented control being returned as event.target it actually returns the parent of the segmented control which in the case of your sample is the stage group. And as you probably insert something else before the segmented control its giving the wrong id.