0

I have made some code for my google map, where I position the camera to one place when the camera is positioned to the first place I toast a message and then I move the camera to another position but the problem is that the toast action doesn't appear for enough time in order to read the message. Is there anyway so I can set the toast lets say for 10 seconds or so ? Here is my code.

          public void onFinish() {
     LatLng 1= new LatLng(x , y);
     LatLng 2= new LatLng(x , y);                               
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();                                         
   map.animateCamera(CameraUpdateFactory.zoomTo(10), 30000,null);

Toast.makeText(getBaseContext(), " I want this message to displayed for 10 seconds.",   
 Toast.LENGTH_SHORT)
 .show();

CameraPosition cameraPosition3 = new CameraPosition.Builder()
.target(1)     
.zoom(16)         

.bearing(300)                
.tilt(30)                   
.build();

  map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition3 ),30000,new  
  CancelableCallback() 

{  public void onFinish() {

 LatLng 2= new LatLng(x, y);

 GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
 map.animateCamera(CameraUpdateFactory.zoomTo(10), 30000,null);
 Toast.makeText(getBaseContext(), " This message for 10 seconds.", Toast.LENGTH_SHORT)                                                
  CameraPosition cameraPosition3 = new CameraPosition.Builder()
 .target(2)     
   .zoom(16)         

  .bearing(300)                
  .tilt(30)                   
   .build();

map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition3 ),30000,null);
Lucifer
  • 29,392
  • 25
  • 90
  • 143
user3449550
  • 123
  • 5
  • 17

3 Answers3

1

Try this surely it will help you i already tried it

   final Toast toast = Toast.makeText(getBaseContext(), "YOUR MESSAGE",Toast.LENGTH_SHORT);
                        toast.show();
                        new CountDownTimer(10000, 1000)
                        {
                            public void onTick(long millisUntilFinished) {toast.show();}
                            public void onFinish() {toast.cancel();}
                        }.start();

got the answer from this question please refer for full details

http://stackoverflow.com/questions/2220560/can-an-android-toast-be-longer-than-toast-length-long
Arun Antoney
  • 4,292
  • 2
  • 20
  • 26
  • This is not correct. The `int duration` parameter is a flag with only two practical values, `LENGTH_SHORT` and `LENGTH_LONG`. – Mike M. Apr 02 '14 at 09:03
  • That won't work either. The Toast will close on its own after 2 seconds. – Mike M. Apr 02 '14 at 09:12
  • Yes, that will work. However, you shouldn't use `getBaseContext()` in this case. Also, you need to give attribution to the SO answer you got this from, or you will be flagged for plagiarism: http://stackoverflow.com/questions/2220560/can-an-android-toast-be-longer-than-toast-length-long – Mike M. Apr 02 '14 at 09:47
  • @Mike M.: Please link to the specific answer that this plagiarizes, instead of to the question, because there are well over a dozen other answers there and it's difficult, even with a search, to find the one you're referring to. – BoltClock Apr 03 '14 at 15:42
  • My apologies, @BoltClock. Thought I had. I believe it's this one: http://stackoverflow.com/questions/2220560/can-an-android-toast-be-longer-than-toast-length-long/7173248#7173248 Hope I didn't mis-flag. – Mike M. Apr 03 '14 at 16:08
  • You can use toast.setDuration(10*1000) – ozmank May 19 '15 at 12:51
0

You'll need to subclass the Toast class and use it. The default class has just two values. Even if you pass a longer time duration, it will we reverted to either of SHORT or LONG

gandharva
  • 691
  • 5
  • 16
0

And this is your toast message in the 1000 is 1 seconds and then that 3rd position is the timing of your toast and then you can show te toast for 10 seconds ...

   Toast.makeText(getBaseContext(), " This message for 10 seconds.", 10*1000).show();
Naveen Kumar Kuppan
  • 1,424
  • 1
  • 10
  • 12
  • This is not correct. The `int duration` parameter is a flag with only two practical values, `LENGTH_SHORT` and `LENGTH_LONG`. – Mike M. Apr 02 '14 at 09:05