I'm struggling as to find out why my .AfterSelection block is not being called. The spinner has several elements. The spinner is visible. On first selection, when any element is selected then .AfterSelection is not called. On any subsequent selection, .AfterSelection is called. I do not provoke the dropdown, it is left to user discretion.
I am not doing anything fancy with the spinner. It's visible and the user is choosing from a list of multiple options, which eliminates the .AfterSelection problems I've seen pop up on this board. I tried to replicate the problem, with a simple app, and was unsuccessful. I've attached the .apk for the entire solution here. The two spinners have the problem, for day and meal. Try making a selection, you will know that .AfterSelection is called from a notification popup, on the second try.
EDIT: To help others help me, I have provided a cut down project file that replicates the problem. The original .apk file has been subsequently removed. Please focus your attention on spnDay.AfterSelection and spnMealType.AfterSelection, which do not get called on the first selection.
--
From the Spinner documentation:
A spinner component that displays a pop-up with a list of elements. These elements can be set in the Designer or Blocks Editor by setting the
ElementsFromString
property to a string-separated concatenation (for example, choice 1, choice 2, choice 3) or by setting the Elements
property to a List in the Blocks editor. Spinners are created with the first item already selected. So selecting it does not generate an After Picking event. Consequently it's useful to make the first Spinner item be a non-choice like "Select from below...". where "Select from below" is an item text you provide for the first item. This is the designed behavior of a Spinner using App Inventor.
The full documentation is here http://ai2.appinventor.mit.edu/reference/components/userinterface.html#Spinner and you can read about.
If you want an object that will behave differently Daniel, consider a ListView or a ListPicker which will fire on all choices, generating an After Picking event.
--
That functionality is what I would expect. However, what I tried to explain in my first post, it will not fire AfterSelection if the second, third, fourth, etc item is selected the first time you try to do so, as replicated in the project file. Only after selecting the spinner the 2nd time does it actually start to fire AfterSelection.
--
I just tested my program with the Emulator and it works as intended.
When I use my HTC One (Android 5.0.2) it does not work as intended.
I feel this particular issue I have has been overlooked by the developers as one of the many of posts on the Spinner, in which the author's failed to understand the spinners functionality. As I can now replicate this working as it should in the Emulator and NOT working on a physical Android device please can a developer confirm they have logged this problem.
--
You can never rely on a spinner after picking event. It will also not fire if you select the same value a second time. Personally I think this event should not have been there for app inventor, unless there were similar events available for text changed events etc. This is an Android restriction, not a bug in AI2.
If you want something that always fires, use a list viewer.
This spinner helps your user to make it easier to fill in a form. Therefore, you need something extra, such as a submit button. On the clicked event of that button, you can read the values of the spinners.
--
I have seen your code and doing something much more simpler than that with the project file for the purpose of replicating this problem.
Could you please try my code using a mobile device. It shows the problem I am having. The behavior is inconsistent compared to using the emulator.
Using AI Companion, please follow these steps, when the app has loaded:
1. Click on the Left <ALL>, which is spnDay.
2. Choose a day.
3. The text is updated to the day selected. The Notification in the .AfterSelection is not fired.
4. Choose another day.
5. The text is updated to the day selected. The notification in the .AfterSelection is fired showing"spmDay.AfterSelection" message.
6. Repeat the above first 2 steps using the emulator, in which the notification message is fired on step 3.
Please can you explain why the message does not appear in step 3, as either 1) this is common to Android or 2) how I'm not using the spinner correctly?
--
Yes, it does appear that Screen.Scrollable is causing a problem when set to false inside the Screen.Initliase block. I have a bare bones project file, see attached, that MIT can look at. Though, what is the best way to contact MIT about this issue?
--
I was testing again a little bit and reduced your example app some more, see attachment
After selecting an item the first time, the AfterSelecting event does not fire, if you set screen scrollable to false and define elements from string in the designer like this
but if you define elements from string in the blocks editor it works fine
so as workaround just define them in the blocks editor meanwhile MIT can take a look at the bug
--
Thank you Taifun. That is a most helpful workaround.
--
I am trying to reproduce the error, and i am wondering if you test this by AI Companion or other stuff. I tried to define elements from string in the blocks editor, but it doesn't work fine too when i am using AI Companion to test.
--
I only tested this using the companion app (version 2.27)
if you use the test example as it is and you select something from the spinner (1, 2 or 3) no notifier will appear (i.e. the event does not fire)
if you now select something else, the notifier appears
now in the designer remove the elements from string and in the block editor enable the disabled blocks and restart the companion app
if you now select something from the spinner (1, 2 or 3) the notifier appears as it should
--
Thanks Taifun, I have successfully reproduce the error on my side. There is one thing i noticed that: after enable that block, if i select "select" item, the notifier will not appears as it should.
--
this is normal, because the default selection index is 1
see also the documentation http://ai2.appinventor.mit.edu/reference/components/userinterface.html#Spinner
A spinner component that displays a pop-up with a list of elements. These elements can be set in the Designer or Blocks Editor by setting the
ElementsFromString
property to a string-separated concatenation (for example, choice 1, choice 2, choice 3) or by setting the Elements
property to a List in the Blocks editor. Spinners are created with the first item already selected. So selecting it does not generate an After Picking event. Consequently it's useful to make the first Spinner item be a non-choice like "Select from below...".
--
Thanks for your such detailed answer!
--
These issues detail this behaviour:
https://github.com/mit-cml/appinventor-sources/issues/361 - Spinner AfterSelecting is now invoked only on every 2nd pick after elements are set using the Elements property setter.
https://github.com/mit-cml/appinventor-sources/issues/442 - Spinner afterSelection not being called when expected #442
--
https://github.com/mit-cml/appinventor-sources/issues/361 - Spinner AfterSelecting is now invoked only on every 2nd pick after elements are set using the Elements property setter.
https://github.com/mit-cml/appinventor-sources/issues/442 - Spinner afterSelection not being called when expected #442
--
댓글 없음:
댓글 쓰기