mit-cml / appinventor-sources

MIT App Inventor Public Open Source
http://appinventor.mit.edu/appinventor-sources/
Apache License 2.0
1.48k stars 2.07k forks source link

Spinner does not trigger AfterSelection when gone #922

Open ewpatton opened 7 years ago

ewpatton commented 7 years ago

From the forum: If a Spinner has Visible = false, one can still open it using the DisplayDropdown method block. After the user selects an element, the AfterSelection event is not fired, but the Selection and SelectionIndex properties reflect the user change.

This is due to how the behavior of the Android Spinner object (relevant StackOverflow post). If the Spinner is View.GONE, it does not fire the onItemSelected callback. One can instead make the Spinner View.INVISIBLE with 0 width and 0 height to achieve the desired effect.

I experimented with adjusting this behavior from GONE to INVISIBLE and it does correct the problem. However, the interaction with the Width and Height mechanisms still needs to be thoroughly tested because View.INVISIBLE still gives the view mass in the layout if the width and height are adjusted when Visible = false or if a percent width/height is assigned and the screen is rotated.

farxinu commented 7 years ago

Another Spinner issue: Say the spinner is set to element 1. You select element 1 (so it becomes Spinner.Selection). After Selecting is not triggered.

ewpatton commented 5 years ago

@mit-cml/cornell-cs-5152-students Here's another opportunity to improve the user experience on the Android side.

Amerkashi commented 5 years ago

@farxinu So, the selection isn't really changed if already on element 1. Android community suggests adding a item as 1st entry. @ewpatton I think the link you provided is private repo

ewpatton commented 5 years ago

@Amerkashi If you were referencing my most recent comment, that was a group mention to tag the students who are working with us from Cornell.

I'm not sure that the proposed solution 100% solves the problem though because the issue is not just about moving from the first element but also subsequent events if you repick the selection. What we need to look into is if we can determine when the spinner is closed so that if the selection hasn't changed we can still trigger the event. Otherwise, it might make sense to rename the AfterSelection event to SelectionChanged to better reflect the fact that it only fires if the selection changes, not after all selections.

elatoskinas commented 5 years ago

I could look into the issue.

However, since View.INVSIBLE generates the view mass, it might be an issue, as mentioned.

Perhaps a viable approach if the view mass is an issue is to have the Spinner as View.GONE and set to View.INVISIBLE when the dropdown menu is opened, and then set it back to GONE when it's closed.