This is a continuation of the discussion from the API page. http://developer.anscamobile.com/reference/index/nativeshowalert [import]uid: 7559 topic_id: 24295 reply_id: 324295[/import]
i have some problems with a few of my alerts. here is my code:
[lua]native.showAlert(“How much fun is this? 1=least fun, 5=most fun:”,object.name,{“1”,“2”,“3”,“4”,“5”},rate)[/lua]
i want the player to pick a number, 1-5. then go to the call back function “rate”
problem is, if the player accidentally taps somewhere on the screen outside of the alert box, the box disappears, the callback function “rate” doesn’t get called and the screen just sits there waiting for a response…which won’t happen because the box is gone.
this is a major frustration for those playing and the only solution is starting over and opening the game all over again.
anyone’s help would be appreciated,
thanks
Amanda
[import]uid: 29997 topic_id: 24295 reply_id: 103148[/import]
Hey Amanda
Being your a test driver I will assume you are using the latest stable build, .704?
Is this problem on iOS or Android devices? Both?
For iOS, I can’t test this myself on that version until I get home, but apps I have on my iPhone using daily build (.773 I think) do not exhibit this problem.
Do you have this problem in the simulator as well? I tested basically what you have above on .704 in the simulator (on windows) and did not have this issue.
The more information you can give the better! [import]uid: 56820 topic_id: 24295 reply_id: 103151[/import]
That’s a good question (using the latest stable build). Doesn’t look like I am. Wasn’t aware there was a newer stable build available…
No problems in the simulator, only when I build for my device, Android 3.0. (and I am building on Mac)
I have a lot of other alerts that are fine. they only have 1 or 2 options to choose from, so I am thinking that is where the problem is (this particular one has 5).
I will try to update Corona to the newest version, maybe this will solve the problem…
This won’t cause any problems for development, right? [import]uid: 29997 topic_id: 24295 reply_id: 103156[/import]
I didn’t really think about that. Quick google search seems to show devices have a limit of 3 buttons. That is probably the problem.
It’s always best to use the latest stable build unless you have a specific reason to use an older version. The only reason I know of would be to target older devices no longer supported. [import]uid: 56820 topic_id: 24295 reply_id: 103159[/import]
I updated, same problem.
The docs say it will support up to 6 buttons, I think.
either way, it doesn’t seem to like using 5.
Would there be a quick fix for this? can i detect when this box is up and if a hit event happens outside of the box? Or I was considering just canceling the alert after a few seconds, assuming that after 10 seconds passes the user has tapped outside of the box and just continuing as though the user tapped something.
The best solution would be to create my own box, but I have a deadline coming up, and unfortunately don’t have the time…
thanks for your response!
(i do like the new version … the simulator supports text boxes! wish I had known about this sooner!)
-Amanda [import]uid: 29997 topic_id: 24295 reply_id: 103161[/import]
Hmm never trust “quick” google searches.
Upon further searching I could not find an actual true device limit.
The way I believe it should work is if an alert box is open, tapping elsewhere will be ignored by the app until the alert is clicked. So I do not think you can detect a click outside the box.
I quickly made a test app with basically your code above, built it with .704, installed it on my Droid and it worked as intended. This may be a bug with your code. Can you post more of the code pertaining to the troubled alerts?
[import]uid: 56820 topic_id: 24295 reply_id: 103166[/import]
I don’t have the code on me at the moment…it’s on my other computer.
The box that popped up, did it cover the whole screen? I have tried it on a phone (droid) and the box that displays covers the whole screen and so I couldn’t tap outside the box. My test device is a tablet, much bigger screen.
I do know, while testing, the callback function “rate” is never called if the person taps outside the box. I have a print statement as the first line, and nothing prints in the log.
I can post more of the code later. I’ll try a smaller test case too. [import]uid: 29997 topic_id: 24295 reply_id: 103197[/import]
Yes, on my Droid there is about an inch of open screen, both above and below the alert box. I can tap all over these areas and even the box itself and nothing happens unless I specifically hit a number button.
This is the code I used to try duplicate your usage. My rate function does nothing though and I do not know what your object.name is.
function rate(event)
end
object = {}
object.name = "My object"
native.showAlert("How much fun is this? 1=least fun, 5=most fun:",object.name,{"1","2","3","4","5"},rate)
On my droid I don’t even see the object.name text as that combined with the title of the box is too long for the phone. In your code, what is object.name? I am curious what happens if you remove that and/or remove the rate function from the alert box ,leaving only the title and 5 buttons. Does it still have the same issue?
[import]uid: 56820 topic_id: 24295 reply_id: 103348[/import]
Everyone,
Alert dialogs on Android only support up to 3 buttons. This is documented on the official Android website here…
http://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog
I’ve looked at the code and Corona will only show the first 3 buttons on Android. The other buttons will be ignored and not displayed. The only possible work-around that I think we can do on our side is if the button count exceeds 3, then we should switch from a button dialog to a list dialog as shown here…
http://developer.android.com/guide/topics/ui/dialogs.html#AddingAList
Would a list dialog as shown by the link above work for you? If so, then I can write it up as a feature request.
In the meantime, the only work-around that I can think of that you can implement “today” is:
- Show a 6 button option in a web popup. Good option if you know have solid web development skills.
- Create your own 6 button dialog using Corona display objects. See our widget API on how to make this easy.
[import]uid: 32256 topic_id: 24295 reply_id: 103367[/import]
The link for the list would definitely work. What’s interesting is the alert box is working, with the code I used. It has 5 buttons, although it does not look like a normal alert box. It actually looks a lot like the list box in your link.
Just an FYI, I created a test case, with the basic functionality of my app, with this code in main.lua:
[lua]function continue()
print(“drag.continue()”)
end
function rate(event)
–when user clicks a number, send number, gender, and id to server
–save id to idArray when completed
print(“drag.rate()”)
print(event.action)
if “clicked”==event.action then
print(" doing stuff …")
timer.performWithDelay(500, continue,1)–timer to start showing conseq/chall
else
print(" not clicked but “…event.action)
print(” need to do stuff anyway!")
end
end
function testing()
native.showAlert(“How much fun is this? 1=least fun, 5=most fun”,“park”,{“1”,“2”,“3”,“4”,“5”},rate)
end
testing()[/lua]
The same thing happens when clicking outside of the box, it disappears (this is on Android 3.0). But what is most exciting is that when clicking outside of the box, the log shows event.action=cancelled and so it enters the “else” condition. This is exactly what I need to know. This doesn’t happen for my app, but I suspect it’s because another display object gets the hit and so the rate callback function doesn’t get executed.
also without the rate callback function, the box behaves the same way.
But the reason being that I tried this type of box in the first place is that in the docs for native.showAlert for Corona list it as being able to handle 6 buttons (I believe).
Thank you for your suggestions, I will plan to change from the alert to one of these soon:)
-Amanda [import]uid: 29997 topic_id: 24295 reply_id: 103376[/import]
Actually, now that I am using the most recent stable version of Corona, if clicked outside of the box, the event does get picked up as “cancelled,” even when clicking on another display object while the alert is shown! The box still disappears, but now I will know when it does:)
Problem solved!
thanks y’all!
amanda vines [import]uid: 29997 topic_id: 24295 reply_id: 103382[/import]
Amanda,
Okay, I was mistaken. It turns out I was looking a the wrong part of the code. Corona actually does show a list dialog… just as you have observed. I must have made that change a while ago and clean forgot about it. *embarrassed*
It turns out that the core Corona code limits the number of buttons to 5 on *ALL* platforms (ie: iOS, Mac, Windows, and Android). So, our API documentation is wrong. I’ll correct the documentation today. Sorry about the confusion.
I tried tapping outside of a native alert dialog on my Motorola Xoom Android 3.x device. I’ve noticed that tapping outside of the dialog cancels it out ONLY if the dialog has been set up with more than 3 buttons. That appears to be the default Android OS behavior. We can change the default behavior to match what it does with dialogs having less buttons. Nice catch by the way.
By the way, pressing the Back will cancel out of the dialog too. That is pretty standard behavior on Android which iOS does not have an equivalent, so watch out for that. [import]uid: 32256 topic_id: 24295 reply_id: 103394[/import]
Amanda,
We changed the code to prevent the dialog from being canceled out when tapping outside of the dialog. It was such an easy change that we went ahead and snuck it in. This change will be in daily build #797. [import]uid: 32256 topic_id: 24295 reply_id: 103407[/import]
Hello guys.
Is there a way to position (x, y) the show alert window on the screen or is it lock to the center of the screen?
Thanks a lot.
Mo
(LairdGames) [import]uid: 100814 topic_id: 24295 reply_id: 104575[/import]
The alert box is positioned at a fixed location and can’t be changed.
Tom [import]uid: 7559 topic_id: 24295 reply_id: 104677[/import]
Thanks Tom. I appreciate the fast response.
Mo
(LairdGames) [import]uid: 100814 topic_id: 24295 reply_id: 104701[/import]
Is it possible to change eg. the alert box contents dynamically (alert.title = “50%”)? [import]uid: 10666 topic_id: 24295 reply_id: 105471[/import]
No, you cannot change the contents of an alert dialog dynamically. In this case, it’s best to construct your own dialog via Corona display objects instead. [import]uid: 32256 topic_id: 24295 reply_id: 105533[/import]
There is a bug in native.showAlert.
You can not add more than 3 buttons to the alert dialog in simulator for windows.
The 4th button can not be seen in the popup dialog.
You can simply test it with the following code in windows simulator.
native.showAlert(‘title’,‘msg’,{‘1’,‘2’,‘3’,‘4’}); [import]uid: 35642 topic_id: 24295 reply_id: 114898[/import]