Is this a bug, or am I missing something?

87 views
Skip to first unread message

Jason Custer

unread,
May 5, 2020, 9:33:38 AM5/5/20
to DroidScript
Hi fellow DSers! The attached is a slightly modified copy of the sample provided in the CreateSpinner documentation. I changed ShowPopup to alert so I could be sure I didn't miss something.

The problem I'm seeing is that the first item selected doesn't trigger the OnChange function. If you select something in the spinner a second time, it works no problem. Tried with OnTouch too, but got the same result.

So, is this a bug, or am I experiencing an id10t error? Maybe it's a pebcak error? I know both are easy to miss.

Thanks!

P.S. If you look at this code, you'll learn a secret about me.

SpinTester.js.txt

Steve Garman

unread,
May 5, 2020, 9:42:09 AM5/5/20
to DroidScript
It is a long-standing feature of the spinner.

The normal workaround is to add a first item to the list "Please select a captain"

Jason Custer

unread,
May 5, 2020, 12:00:05 PM5/5/20
to DroidScript
Hey there, thanks for getting back to me. I did as you suggested, I think, but still see the same error. To be clear, no matter what I select, the first time does nothing. IE, open the app, choose any captain, see nothing happen. Choose another captain, see an alert box, this works any time thereafter. I'm using beta, but didn't want to post there because I wasn't sure if it was something I was doing wrong.

Thank you again, looking forward to your responce.

SpinTester.js.txt

Jason Custer

unread,
May 5, 2020, 1:16:30 PM5/5/20
to DroidScript
After checking out the DS wiki, I found this little nugget. "If the SelectItem method is called before the spinner and the layout is added to the app-object the OnChange event of the spinner is fired only after the second manual selection change." This also seems to be true of SetList. The attached code works perfectly, so this seems to be the problem. I didn't see this in the official docs.

Thanks.

SpinTester.js.txt

Steve Garman

unread,
May 5, 2020, 1:27:10 PM5/5/20
to DroidScript
Thanks for posting that Jason.

I had just tested your code and had a sense of déjà vu but could not find a previous discussion.

We great grandparents can't hold all our acquired wisdom in our heads simultaneously.
That's how I intend to describe it anyway.

Dave

unread,
May 6, 2020, 6:25:01 AM5/6/20
to DroidScript
Hi Jason. there appears to be a bug related to calling SetList and SelectItem right after each other.  The spinner is a bit complicated internally as it has to use a counter to prevent setting the list or current list item in code from firing the callback.

If you set the list when you create the control the problem goes away.  Like this:-

function OnStart()
{
 lay
= app.CreateLayout( "Linear", "VCenter,FillXY" );
 spin
= app.CreateSpinner("Please select a captain, Kirk, Picard, Janeway", 0.4 );
 spin
.SetOnChange( ShowSelection );
 
 spin
.SelectItem( "Picard" );
 
 spin
.SetOnTouch(touch);
 lay
.AddChild( spin );
 app
.AddLayout( lay );
 
} //onStart


function ShowSelection( item ) {
alert
( "Selected = " + item );
}


function touch( item ) {
alert
( "Touched, Selected = " + item );
}


I'll try to fix the problem.

FYI: SetOnTouch and SetOnChange are the same thing but one of them is deprecated.  I can't remember which one right now, but OnChange would be a better description of what happens.



Dave

unread,
May 6, 2020, 8:42:24 AM5/6/20
to DroidScript
P.S. You need to remove the spaces after the commas from your list or the   spin.SelectItem( "Picard" ); won't work.
Reply all
Reply to author
Forward
0 new messages