Is it normal for Spinner component to automatically set the first item as selected in my application? The Selection field is empty.
You could show your blocks that reproduce the issue ?
I know that Spinner does not execute blocks in AfterSelecting when we choose the same element as before. Why doesn’t blocks execute in AfterSelecting the first time the Selection field is filled? At the beginning the Selection field is empty. I enter “two” in the Selection field and the AfterSelecting block does not execute.
These blocks not work.
Yes, but after the Checkbox is checked, the Spinner.Selction is "two".
As you wrote: I know that Spinner does not execute blocks in AfterSelecting when we choose the same element as before.
In your second attempt:
Since Spinner1-Selection changes from "two" to "one", Spinner1.AfterSelection event is triggered, otherwise not.
What exactly should be achieved?
According to me, if Selection is empty at the beginning and then we set Selection to “one”, then blocks in AfterSelection should also be done, because there is a change from empty to “one”. It would not be possible to change the Spinner element code so that before making the selection, the selection was empty? Initial values Selection = empty, SelectionIndex = 0? In the application, before the selection, the text (hint) might appear, e.g. “Make a choice …”. This possibility is e.g. in code websit. Then it would be possible to make an AfterSelection block even when ElementFromString has only one value. I did using the ListPicker element. It is a pity that ListPicker does not open in a POPUP window like Spinner, or Spinner does not work like ListPicker.
This how I usually handle the spinner’s odd behaviour
The button and the spinner are inside a horizontal arrangement set to vertically centred (to hide the spinner arrow) - with the spinner component set to 1x1 pixels and placed to the right of the button.
All this is why I use List Pickers instead of Spinners.
In one of my applications I use the “Spinner” hiding method in “HorrizontalArrangement” set to “1px x 1px”. Unfortunately, the arrow is still visible. Samsung S8, Android 9.
A few situations where the spinner arrow, when set to 1x1pixels in size, can be made to “disappear” with Device Default theme…
Place the spinner directly on a screen that is aligned left
Place the spinner to the first component on the left inside a horizontal arrangement that is set to fill parent, aligned left
Place the spinner to the right of another component inside a horizontal arrangement and set the horizontal arrangement to vertically centred
Spinner (1x1px) needs to be below another component sized at @ 2px in a vertical arrangement set to 1px high
Try this, it doesn't matter where the spinner is placed. It is also not necessary to set the Spinner to 1px:
spinner_noArrow.aia (1.9 KB)
Thank you. It helped. In the horizontal system it works too. Earlier I used the button to cover. The button has a transparent image so the arrow was visible under the button. :szeroki uśmiech: :szeroki uśmiech: Sometimes I have to combine a lot with graphics to achieve the goal.
I read the other topic with this name.
But more simple block: It should show the selection in a label. (if it is another choice)
Why does this not work?
Do you have the spinner set to not visible? It won’t work. The spinner has to be visible.
Thanks. That works.
Now I remember an other topic, saying to make the spinner visible with width 0
Maybe someone could add to http://ai2.appinventor.mit.edu/reference/components/userinterface.html#Spinner or .DisplayDropdown()
The spinner works only if it is visible. The DisplayDropdown() only fires, if a new item is selected.
I guess, I am not the only who search here after nothing found in the reference.
AHA ! Thats quite clever. Ok. I think I can make that work for me.
But surely the ‘after selection’ block SHOULDN’T BE OFFERED if it doesn’t / can’t work !!
Wouldn’t it be best if the blooming thing just worked the way it purports to ? Can we ask MIT to fix it?
Either 1. The ‘bug’ is fixed.
Or 2. MIT explain why spinners ‘function’ the way they do. (in the popup guidance notes maybe…)
If I understand correctly, if one chooses to use a spinner, then there will ALWAYS be a choice selected for you? It seems with a load of convoluted programming to get around a simple mishap, a List picker would be the prefered option.
It would be simpler, no, if the PTB eliminated the forced selection, such as a List Picker.
Yes and No...
If you add elements to a spinner, it will display the first element on the drop down button and this will be the selection. If you select the first item from the drop down, the afterPicking event does not fire.
The spinner component comes from android, not from MIT, so your PTB are a bit further up the chain. Ever got a response from Google directly if you have a feature request ?
Depending on what you want to do, follow this guide:
Once setup, it will work for you, probably as you require....
Thanks Tim. Sounds like the way I usually do it, with adding the 1st item and then coding out after a selection is made.
Always curious, just wondered if there was a native option to eliminate the pre-made choice that I had missed.