How to set the Spinner relative to the element it was set?

111 views
Skip to first unread message

Xiaomy Redmii

unread,
Feb 27, 2019, 12:39:10 PM2/27/19
to MIT App Inventor Forum
the spinner after it was chosen and close 
and back to the app again 

the spinner go to default not on the thing it was set


need help to save the recent it was set thank you

TimAI2

unread,
Feb 27, 2019, 2:22:45 PM2/27/19
to MIT App Inventor Forum
Please show your blocks for this, it does not sound like the default behaviour for the spinner...

SteveJG

unread,
Feb 27, 2019, 5:01:23 PM2/27/19
to MIT App Inventor Forum

Xiaomy Redmii

unread,
Feb 27, 2019, 7:31:04 PM2/27/19
to MIT App Inventor Forum
I want the selected elements in the spinner to stay even I close my app

but in my case now it was going back to it's default

SteveJG

unread,
Feb 27, 2019, 7:40:05 PM2/27/19
to MIT App Inventor Forum
If you need the values to 'stay even I close my app' then you need to save those values in a TinyDB.  When you turn the app back on, use the Screen1.Initialize block to set the Spinner element selected and the "saved" value

Xiaomy Redmii

unread,
Feb 27, 2019, 7:53:46 PM2/27/19
to MIT App Inventor Forum

admin_part.png


TimAI2

unread,
Feb 27, 2019, 8:21:14 PM2/27/19
to MIT App Inventor Forum
You don't show us how your are changing the spinner elements, or to what ?
As it stands, you will get the default selections for all your spinners when the app is started
Do as Steve suggests and save your alternatives to a tinydb and call these from screen initialise

I see you are up to at least Screen9, hope you haven't crossed the boundary above Screen10, otherwise you may start having other/additional problems with your app

SteveJG

unread,
Feb 27, 2019, 8:41:09 PM2/27/19
to mitappinv...@googlegroups.com
You are saving values to Firebase, so the values should be saved on Firebase with a Tag.   If the values are saved in  Firebase, use the Firebase GetValue(text tag, any valueIfTagNotThere)
GetValue asks Firebase to retrieve the value stored under the given tag. It will pass valueIfTagNotThere to GotValue if there is no value stored under the tag.
Use the GetValue block for the Tags you want  in the Screen1.Initialize  block   and then update the 'position' of the spinner perhaps?   The 'value' should already be saved in Firebase under a Tag like trashoff1 , trashoff2, trashoff3 . and could allow you set the Spinner 'selection'  to manipulate  Spinner .    Remember, you need to use the when Firebase1.GotValue block to actually capture the value of the Tag and probably save it to a variable.  Use the variable to set the Spinner 'selection'  Tag    or do you want to use the value?


 Be aware Spinners are created with the first item already selected. selecting an element with code 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...".      You might experiment. set Spinner.Selection to might work but it won't activate unless you 'touch' the selection.   I don't remember, but if you do that, you might not generate an afterpicking event for an already selected element ...That might be why you are not getting the results you desire. A Spinner is a difficult control to use.   You might do better just to use an array of three check boxes.

Tim is cautioning you about the number of Screens; I second that...you are inadvertently creating a programming nightmare but certainly, that is your choice.






Xiaomy Redmii

unread,
Feb 28, 2019, 9:50:35 AM2/28/19
to MIT App Inventor Forum
sir 

how can I implement check box?

I know I can save it on the firebase

but how I can use it based on my desire ?

Xiaomy Redmii

unread,
Feb 28, 2019, 9:57:31 AM2/28/19
to MIT App Inventor Forum

gotvalue.png


SteveJG

unread,
Feb 28, 2019, 10:12:11 AM2/28/19
to MIT App Inventor Forum
Array of Check boxes
see       https://groups.google.com/forum/#!msg/mitappinventortest/i4MJIXFIWoA/J1AntfBCCbkJ;context-place=searchin/mitappinventortest/checkbox$20steve$20groupbox%7Csort:date

and  


Saving the state of the checkboxes so the correct one is indicated when the app is restarted

 see the 3/20 post by Time in this discussion to save the 'state' of the checkboxes   https://groups.google.com/forum/#!msg/mitappinventortest/TZMJy2t9uIM/ctrtrIYeAQAJ;context-place=forum/mitappinventortest 

shows how to save the 'state' of the checkboxes on the device using a TinyDB.    The 'state' of the checkboxes could also probably be saved in the Firebase itself with more complexity.


" how I can use it based on my desire ?" ..sorry, we do not really understand what you want to do or why you want to do it.

You might also like to review a recent Forum tutorial posted by Tim ... https://groups.google.com/forum/#!category-topic/mitappinventortest/K-zAr2X3nio    that might help you with your total Project.




Xiaomy Redmii

unread,
Feb 28, 2019, 10:42:40 AM2/28/19
to MIT App Inventor Forum
I use the spinner to have a choice which screen will assign the RESULT of QR CODE (Maintenance Officers)

then still the spinner chosen will stay even the app close

I use firebase to save the data and be access by all the app user

but the problem it wasn't still use in my app




TimAI2

unread,
Feb 28, 2019, 10:45:44 AM2/28/19
to MIT App Inventor Forum
Also, if you want more control over what the spinner is doing see here:

Reply all
Reply to author
Forward
0 new messages