• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Toast.SetDuration()

phil_mw60

Lurker
Hi,

Does anyone know if it is possible to specify a custom timeframe in milliseconds using the Toast.setDuration() method?

apart from Toast.LENGTH_LONG & Toast.LENGTH_SHORT?

I have experimented with Toast.setDuration(10) and Toast.setDuration(1) in the hope that the message would flash up and then disappear very quickly (I am looping through records and it should give a general idea of which record is currently being processed) however even with an argument of 1, the toast message seems to stay on screen for at least a couple of seconds.

Thanks in advance for any ideas!

Phil




 
I don't have a solution for you, but the LENGTH_SHORT and LENGTH_LONG are not time values. They're constants used as flags. You'll notice that the actual values of those fields are 0 and 1, respectively. The documentation says that the time could be user-definable, but there are no public methods to do so. My only idea would be to try extending the Toast class and see if you can expose any more of the underlying details that way.
 
For what you're trying to do, it makes a lot more sense to have a TextView that you control and directly update instead of creating Toasts repeatedly. Every time you make a Toast, you're running this (among other things):

Code:
LayoutInflater inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflate.inflate(com.android.internal.R.layout.transient_notification, null);
TextView tv = (TextView)v.findViewById(com.android.internal.R.id.message);
tv.setText(text);

So that's a lot of Views to create and throw away when you can easily be reusing an existing View.
 
Back
Top Bottom