views:

1452

answers:

4

When using setDuration for a Toast is it possible to set a custom length or at least something longer than Toast.LENGTH_LONG?

+1  A: 

Try this

Toast tag = Toast.makeText(this, "blah", Toast.LENGTH_LONG);
tag.setDuration(5);
Vinayak.B
Thanks, but this is what i was trying. No luck
StatDroid
A: 

You can find the documentation for Toast widget here :

http://developer.android.com/reference/android/widget/Toast.html

Michaël
+2  A: 

The values of LENGTH_SHORT and LENGTH_LONG are 0 and 1. This means they are treated as flags rather than actual durations so I don't think it will be possible to set the duration to anything other than these values.

If you want to display a message to the user for longer, consider a Status Bar Notification. Status Bar Notifications can be programmatically cancelled when they are no longer relevant.

Dave Webb
Thanks for the suggestion about the status bar, but im going with a custom dialog activity.
StatDroid
Suggestion with firing toast.show() multiple times is way better...
kape123
+2  A: 

If you want a Toast to persist, I found you can hack your way around it by having a Timer call toast.show() repeatedly (every second or so should do). Calling show() doesn't break anything if the Toast is already showing, but it does refresh the amount of time it stays on the screen.

iandisme
http://thinkandroid.wordpress.com/2010/02/19/indefinite-toast-hack/
kape123