toast problem with many clicks

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

toast problem with many clicks

Postby Benkr0n » Sat Feb 06, 2010 10:47 pm

i have a button that if criteria are not met it displays a toast message with duration SHORT
this works like its supposed to...

but what happens when the button is clicked many times...
the toast message stays on the screen for a really long time, depending on how many times it was pressed.



is there a way to limit the amount of toasts appearing on the screen?
or make my button work only every "X" seconds?
Benkr0n
Junior Developer
Junior Developer
 
Posts: 18
Joined: Fri Feb 05, 2010 6:45 pm

Top

Postby mitutitu » Tue Feb 09, 2010 7:13 am

Hi Benkr0n, in that case you can set a boolean flag to control this scenario. Get the time of your device when a click is made and save it to a variable. And every time a click is made compare two timestamp and check whether it meets the time difference that you've allowed for it to show the toast. I think this can be an approach for controlling your toast appearence. There can be other ways to control it.

let me know if it is worked.

Have fun :)

Thanks,
mitu
User avatar
mitutitu
Senior Developer
Senior Developer
 
Posts: 113
Joined: Tue Jun 09, 2009 7:40 am
Location: St. John's, NL, Canada

Postby Benkr0n » Tue Feb 09, 2010 6:39 pm

A flag would work... I guess I'm looking for a simpler solution.


If anyone can help me understant the [cancel()] feature of toast...
It says:
Close the view if it's showing, or don't if it isn't showing yet.


That sounds almost exactly like I want. But I don't know how to impliment it into my code.
Benkr0n
Junior Developer
Junior Developer
 
Posts: 18
Joined: Fri Feb 05, 2010 6:45 pm

Postby azraeal » Wed Feb 10, 2010 12:16 am

I assume your old code is to the effect of:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Toast.makeText(...).show();
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

and also there is only 1 toast.

Store this toast as a variable then on each click, call cancel() followed by show().
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Toast myToast = Toast.makeText(...);
  2.  
  3.  
  4.  
  5. public void onClick(...){
  6.  
  7.    ...  //logic
  8.  
  9.   myToast.cancel();
  10.  
  11.   myToast.show();
  12.  
  13. }
  14.  
  15.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
azraeal
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Sep 04, 2009 6:34 pm
Location: California

Postby Benkr0n » Wed Feb 10, 2010 4:33 am

i tried adding cancel() two ways:

myToast.cancel();
myToast.show();

what this does, instead of a 'stream' of toasts the duration finishes and then starts from the next button click.

myToast.show();
myToast.cancel();

if you click the button nothing will show up... but if you click it again during the duration it will pop up, and on multiple clicks, behaves like the first example


so i'm probably interpreting the description wrong and this doesn't work
anyone else with some insight?
Benkr0n
Junior Developer
Junior Developer
 
Posts: 18
Joined: Fri Feb 05, 2010 6:45 pm

Postby mitutitu » Wed Feb 10, 2010 6:48 am

Hi Benkr0n,

I think you should use dialog instead. Toast is meant to be used for other reason in android application framework.
It says:

A toast is a view containing a quick little message for the user. The toast class helps you create and show those.

When the view is shown to the user, appears as a floating view over the application. It will never receive focus. The user will probably be in the middle of typing something else. The idea is to be as unobtrusive as possible, while still showing the user the information you want them to see. Two examples are the volume control, and the brief message saying that your settings have been saved.


So in response to button click dialog is best suited instead of Toast. This is only my opinion.

Thanks,
mitu
User avatar
mitutitu
Senior Developer
Senior Developer
 
Posts: 113
Joined: Tue Jun 09, 2009 7:40 am
Location: St. John's, NL, Canada

Top

Postby azraeal » Wed Feb 10, 2010 7:20 am

Benkr0n wrote:i tried adding cancel() two ways:

myToast.cancel();
myToast.show();

what this does, instead of a 'stream' of toasts the duration finishes and then starts from the next button click.

Is this not a proper solution to your predicament? If the user is, pardon, dumb enough to keep clicking even with an error or status message saying "we're busy" or "don't click me", then they completely deserve to keep seeing the toast for as long as they keep clicking.

myToast.show();
myToast.cancel();

if you click the button nothing will show up... but if you click it again during the duration it will pop up, and on multiple clicks, behaves like the first example


This should show nothing because you cancel it immediately after. You might be seeing a race condition.

Because you are just doing a simple toast, and not some critical calculations, even your original implementation would be acceptable. As a programmer, you should account for user stupidity so your program won't break. But since nothing is being broken, and it's all aesthetics, you need to weigh the benefits.

I recall someone on these forums mentioning the native dialer app crashes after flipping the phone (G1) open/closed 40+ times. Was it made to be used in such a way? No. Could it have been handled better? Yes. Was it worth it? Not at the time.
azraeal
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Sep 04, 2009 6:34 pm
Location: California

Postby Benkr0n » Wed Feb 10, 2010 7:31 am

I agree about user stupidity... but like you said, accounting for all possibilities...

At this point I'm not going to worry about it and focus on more important things.



Lol at 40+ open/closes
Benkr0n
Junior Developer
Junior Developer
 
Posts: 18
Joined: Fri Feb 05, 2010 6:45 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests