1. Check out our companion app, Forums for Android! Download from Google Play


Discussion in 'Application Development' started by phil_mw60, Aug 31, 2010.

  1. phil_mw60

    phil_mw60 Member
    Thread Starter

    Jul 28, 2010

    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!




  2. LeffelMania

    LeffelMania Active Member

    Jul 13, 2010
    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.
  3. 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 (Text):
    1. LayoutInflater inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    2. View v = inflate.inflate(com.android.internal.R.layout.transient_notification, null);
    3. TextView tv = (TextView)v.findViewById(com.android.internal.R.id.message);
    4. tv.setText(text);
    So that's a lot of Views to create and throw away when you can easily be reusing an existing View.

Share This Page