2017년 4월 3일 월요일

Using spinner to select new screens?!


I am trying to create a test app which has 3 screens, each screen with its own player/sound that starts as soon as the screen is opened. I simply want to be able to select any of the three screens from the spinner, but am finding it increasingly difficult. I have scoured the web for tutorials on the spinner and most of them only contain basic info that I already know. Can anyone help? I've attached my blocks screen, and I'm sure it is just the case of missing blocks! 





--
and most of them only contain basic info that I already know
so if you already know the basic info, why don't you use the Spinner.AfterSelecting block together with the Spinner.Selection or Spinner.SelectionIndex to find out what has been selected?

-- 
Thanks for your reply, Taifun. Sorry, my screenshot didn't include all my blocks. I have tried using the spinner.afterselecting block, but I am struggling to link the Spinner.SelectionIndex and Spinner.selection to specific screens. I have only managed to make the entire spinner (when clicked) go to a different screen.

I should also qualify that when I say 'basic info', I mean really basic. I have yet to find a tutorial that covers spinner selection >>>multiple screens. 

--
I should also qualify that when I say 'basic info', I mean really basic. I have yet to find a tutorial that covers spinner selection >>>multiple screens. 
Do the tutorials to learn the basics of App Inventor.


You will not find a tutorial, which does exactly what you are looking for. But doing the tutorials (not only reading a little bit) help you to understand, how things are working. This is important and this is the first step to do. 

in your case you can for example use the SelectionIndex like this
if Spinnner.SelectionIndex = 1
then open another screen Screen1
else if Spinner.SelectionIndex = 2
then open another screen Screen2
etc

alternatively use the Spinner.Selection

-- 
I did make the mistake of choosing to do some tutorials and not all, so I will work on them next.

As for the selection.index, is the attached correct? The spinner is still unresponsive with those commands, am I missing a line?

ps. The correct file is now attached



--
I prepared a small spinner example for you
to open another screen, just add the open another screen block...

--
Many thanks for this, Taifun. In addition to the tutorial, this kind of help is priceless for beginner app developers.

--

Spinner .AfterSelection not being called when expected


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 theElementsFromStringproperty 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.

--
see my spinner example here: Using spinner to select new screens?!

--
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?

--
I played around with your example and if I set the screen to scrollable = true it works fine

very strange... 
you will have to prepare an example as small as possible which demonstrates this issue for MIT to take a look...

--
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

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 theElementsFromString 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 


--

How to use a TinyDB to store datepicker, spinner and timepicker?


Hi, I have know idea how to create a TinyDB to store datepicker, spinner and timepicker.

I want the Reserve button to store the information on what is put on the datepicker, spinner and timepicker by using a TinyDB.

Could somebody please help me?






--
TinyDB
ABG's example    Build Your Own DB - Part 1   demonstrates filtering

Stephen's example    TinyDB - a persistent data solution

--
Thank You 

--

spinner "error message: bad arguments to is text empty?


I need some help with the following coding. I am trying an easy if --> then --> else solution. But regarding to the spinner it might not be easy as it seems. 

In my App solution it is not allowed to change the screen, if there is no item selected from spinner1, spinner4, spinner5 or spinner6. 

In my case, when no item is selcted there will an alert "Please select an item."

But it won`t work. In stead of my alert message the following error occurs.
It seems, that an item has to be selected, before another action can be done. Maybe some one has a better solution or an great idea.
Thanks in advanced.

-- 
set the spinner selectionindex to 1 in Screen.Initialize (or to any other default value you like)

-- 
Great! 

THX

--

Test Release Testing is Over - 134a Released!


The MIT App Inventor Team would like your help in testing a new version of App Inventor 2.

We have made extensive changes to the BlocksEditor specifically to improve the stability and performance when loading projects that contain a large number of blocks. We have done a lot of testing both internally and with small groups, but it is now time to test this version on a larger scale and are asking for your help.

This version is for TESTING ONLY and should be used at your own risk. We cannot guarantee that projects created with this version will be saved or work with our general production App Inventor 2 service. With that said I would like to assure our community that there has been no changes that would require current projects to change or break once we release this version on our production service.  We are merely looking to our community for help to find bugs and inconsistencies. 

To report bugs and give comments please use the MIT App Inventor Forum and remember to indicate in your posts that you are using the ai2-test version. 

You can find this new version at the following URL: 


Thank you for your help the MIT App Inventor Team.

-- 
Awesome! I thought my computer was freezing...
Is there a way of copying a project I'm working on (ai2) to the test app inventor?

--
Yes, save the project to an aia file. and then open that aia file in the test site.

HOWEVER, you cannot bring that file back into the production system right now, so make sure you make a copy that you can still use just in case.  DO NOT MIX THE TWO UP...

The test site is a TEST site.  Do NOT work on production work in the test site as it may NOT be able to be brought back to the current production system.

Once you have saved your AIA file from the production system, you can IMPORT it into the test site...  Do NOT import it back into the production site.

READ THE SPLASH SCREEN NOTES WHEN YOU LOG ON, BEFORE YOU CONTINUE.

To Export Your Project to an AIA file...


1. Click on the My Projects link at the top of the UI:
2. When the list of projects shows up, put a check mark by the project you want to export
3. Then click on the Project link (notice that they're similarly named but not the same)
4. Choose Export selected project (.aia) to my computer...
That's it.  The file will be saved where all of your other downloads are saved, and it will have the format YourProjectName.aia!

--
Played with it for 10 minutes on a large project 
formerly it was taking several minutes to move each block.
Now I can't even perceive the delay.
BRILLIANT !
will test further and submit any comments via the forum
Thankyou AI team, great work as usual.

--
I also loaded some large projects and for moving blocks didn't have any problems; great job.

--
This project used to lag when dragging blocks and the click sound when joining blocks would be delayed as well.
Everything now drags and clicks with no delay.
Nice work!

--
Thank you! !! I realy appriciate the work but i also have to say i learned alot by trying to avoid lag with DRY programing.
Now its super fast wuhu :)

--
help me.
how to add component??

--
This is awesome, thanks for the continual improvements. Have only tried it briefly but instantly saw an obvious difference.

Now if we could just make a long variable pull down list scrollable, that would also increase productivity. Currently, once the list bleeds off the bottom of the screen there is no way to get to the rest of the list.

--
Definitely a big improvement in performance on my large project.  However, I'm concerned going forward with it on the beta.  I understand not to count on the saves in the beta version, but will we be able to import any aia files we export from the beta into the non-beta version of this when it goes live officially?

--
Wonderful,itch works perfect,its a great progress.VERY VERY VERY THANKS YOU,CONGRATULATIONS.

Will its be possible to solve the memory problem in the near future.

--                  
My Name is V.Jayakrishna Reddy, I have lost Money I have only typed data in your application. I have Logged you a complaint that  money has lost in Andhra Bank mobile banking(Anroid Application) .I am from Kurnool, Andhra Pradesh, India.
My Anroid Application name is  Andhra Bank Netbanking Invented with MT App Inventor appinventor.mit.edu
My data has hacked somebody from online (Anroid Mobile Phone application  hacking )
First step: id: Password Next txn password
second step : Atm Card Details 
third step : OTP  number /password
Please reply for this as early as possible yours Jayakrishna 8886948132
My Mail Id is         krishnajo...@gmail.com
Finally!! yes! great improvement. I loaded a very big project, which usually took seconds (10-15) to react when I was doing something, I was so frustrated that I stopped the developing waiting for...this!

AI2-test is quick (I use Chrome), with really good responses. 
The only litte issue (not really a bug) I see is that, when you have collapsed blocks and you click on expand, the first time the block is expanded it looks weird (see attachment), but after re-collapsing and re-expanding all is fine




I am going to make some more test in the next few days.

--
As i see if you add functions like the new spinner in old projects, it can't be loaded to Ai2 - test, at least for me, but i want to thank you a lot, the App Inventor made my life easier =P, and the Ai2 - Test is really fast, even with a lot of blocks (sorry for my english, not main language)

--
The AI2 instance at ai2-test does not include the recently added components like Spinners, etc. However, we are working on a release for the near future that will combine the performance advantages of ai2-test with the new components. 

--
app inventor 2 is great,
the blocks are online,
no need for java,
and no need for cables to connect and run a test,
just get the code and use the companion
to run a simple test.

you are just great!

make a simple way to put ads,
and you will be too greaaaaaaaaaaaaat!

--
I am working on a project at URL http://ai2.appinventor.mit.edu  which has this About information:

Built: May 26 2014 Version: nb134
Use Companion: 2.19ai2zx1

In the Blocks page, my project is about 3-4 "pages" long (as one scrolls down the blocks webpage).

When I first started, all was well, but at this point, anytime I (1) move any piece around even single control or variable or basic piece, or (2) click on a variable field to name it, or anything really,
Firefox goes grey for a couple moments, then finally comes back, so I can then continue.   In short, it takes me 2-3 hours to do what should be 30 minutes work.   

The ai2-test site is already an older build than the ai2 site I am working at. 

What am I missing here???  How can this issue be fixed???

--
you are working on the live system of AI2
one possibility is to try Google Chrome instead

did you test your project in the test system, too http://ai2-test.appinventor.mit.edu
How is the response time there?
You can test on the test system in case you do not use the new features, which have been added May 18th. http://appinventor.mit.edu/ai2/ReleaseNotes.html

generally: there might be some redundancy in your project?
probably it helps to read chapter 19 - 21 in Dave's book http://www.appinventor.org/projects to get an idea how to do DRY programming with App Inventor https://en.wikipedia.org/wiki/Don%27t_repeat_yourself

--
Thank you for the info, I'll look through it.

To answer your question, I saved my project to .aia file from the ai2 site, and attempted import to the ai2-test site, but got a big warning on the screen, that the ai2-test site was an older build, and may not be able to load all of my app successfully - which it turned out, it was missing all of it but one variable initialization piece.   :(    That is when I compared the Help / About information in both, and found the ai2 was a newer build than the ai2-test site.   It did seem to matter when attempting to import my project for testing.

And I was going to post this first, then try Chrome, but as I have it installed tried it, and forgive my caps, but WOW!!  - night and day difference.  The lag went totally away using Chrome rather than Firefox.   This is on Ubuntu 14.04 Linux version. 

Thank you greatly.  :)

--  
Addendum to my last post above.  

Not sure this is the correct forum section for this (but since this is where we find info about the Ai2-test site), what is this issue with the 5 or 5.5 MB .apk file limit ?    Is this an Ai2 issue, and if so is it being addressed ?   Or the limit being increased?   (Google allows 50mb .apk if I am not mistaken.)   

Also, I have read two diverging matters concerning this limitation, one is that it is a .apk build issue related to server timeout, and secondly that it is an application issue when installed on Android, that the app can have trouble - example work ok at first but begin to lockup in some ways.       Can you shed some clarity on this?  

--
The 5MB limit will NOT be increased in the foreseeable future.

The limit applies to all the test and production sites, but there are ways around it.  Usually, when your app gets that big, it's because of added assets... Here are some solutions from Hossein & Taifun on Taifun's pages: http://puravidaapps.com/filebyfile.php

In actuality, your blocks lag has NOT gone away by using Chrome.  It's visibility is diminshed, but both browsers are running the same code.  Chrome does it more efficiently than Firefox.

The test site IS older.  It was built to try to correct the lagging issue, which it clearly does.  The development team is working on getting all of those changes integrated so that they can be part of the production site.

--
Will you update the ai2-test to accept the projects of ai2 with the new functions available?

--
No... The test was primarily to address lagging issues.  That code will soon be merged into the production system, although I can't tell you when, but soon I think.

You can test the "test" system referenced here with projects that don't contain the new components, but fairly soon, the speed enhancements exhibited in the test release will be incorporated into the production system, and then you should have the best of both worlds.

--
Thank you (a lot), can´t love you and Taifun more... =D

--
Really nice work! I'll wait for the next release. For me works fine :)

--
The test is over, and the merge has been completed!  The current production version, nb134a is now live and incorporates all of the speed tweaks!

Please see the release notice at the top of the forum!

--

HELP FOR THE SPINNER BLOCK AND CONNECTION TO DATABASE AND CONNECTION TO ARDUINO


Please I just want a help with my application where it should be calculated based on the formula below.

I don't know how to do if the weight is in kilograms or lbs. and in height how can i get if it is in cm or inches using the Spinner Block.

Also I don't know if it will work together with the arduino to count footsteps and also how can i create database.

Thanks for the BIG help, very much appreciated.

W = weight in kilograms (weight (lbs)/2.2) =weight in kg
H = height in centimeters (inches x 2.54) =height in cm
A = age in years

Men: BMR=66.47+ (13.75 x W) + (5.0 x H) - (6.75 x A)
Women: BMR=665.09 + (9.56 x W) + (1.84 x H) - (4.67 x A)


SMARTPHONE_APP.aia

--
Search the forum! This same question had been asked before, and anyway you would spoil all the fun for yourself if you would not try to learn some app inventor first.
And if you post an .aia, post also a screenshot of the blocks, usually it spares us the need to open your .aia

--
============> Your blocks did not copy in the right way. So they are not here.

​Here's the updated blocks.

I don't know what's wrong with this blocks. I Know my formula was right.

Help me with this problem.

================= Your reply was not posted, apparently because you sent it to me privately and only cc-ed the forum.
And I saw that it was you who posted this question earlier. Why did you not continue on that thread?

Anyway, I cannot help you if you do not say what the problem is. If you do the calculation, does it give the wrong values? Did you try DoIt to find out where it goes wrong?
What does this formula mean, anyway? What does BMR stand for?

One thing I noticed: global gender is 66.47 for males and 665.09 for females. Is there a 600 times difference between males and females? How?

--
See attached for how to nest expressions, and how to name variables, parameters, and functions by purpose and type, for clarity.

I left calling the choice of function based on sex to you.

You can copy the blocks across projects 
using the BackPack.



--
Sorry for the inconvinience. here is the block I've created



--
Sir, thanks for your help.

But I've created a spinner for the selection if the height is for inches or in cm. and for the weight in klg or lbs.
for the user to choose whether what's is he/she going to select.

--
Your problem is this:
You cannot be sure that the "when Spinner.AfterSelection" is ever called, because if the default selection is already what the user wanted, there is no need to call it.

You can do eithor of two things:
1. Make the selection initially something like: "please choose ...". You must then when calculate is clicked test whether the user made a selection (selectionIndex not equals 1) and show an error message if not.
Or:
2. The other way is not to bother about the AfterSelection blocks and do all the calculation in the "when Calculate.Click" block.

--