2016-05-24 73 views
1

我有一个应用程序,以显示与特定的持续时间和具体时间举杯显示下烤面包和随机显示上显示, thath的工作安全,但不显示在祝酒数组项。 怎么办? TNX如何显示数组中的吐司

//MyReceive 
public void onReceive(Context con, Intent mIntent) { 

    mContext = con; 
    final String[] array = { "1", "3", "4", "5", "6", "ffff","END"}; 


     final Handler mHandler = new Handler(); 
     mHandler.postDelayed(new Runnable() { 
      @Override 
      public void run() { 

       Random r = new Random(); 
       int i1 = r.nextInt(Activity_Main.w); 

       r = new Random(); 
       int i2 = r.nextInt(Activity_Main.h); 
       Log.d("tag : ", i1 + " : " + i2); 

       for (String arr : array) { 
        t1 = Toast.makeText(mContext, arr, Toast.LENGTH_SHORT); 

       } 

       //delay in show toast duration 100ms 
       Handler h = new Handler(); 
       h.postDelayed(new Runnable() { 
        @Override 
        public void run() { 
         t1.cancel(); 
        } 

       }, 100); 
       //random location on screen 
       t1.setGravity(Gravity.TOP, i1, i2); 
       t1.show(); 

       //delay in show next toast 
       int min = 3; 
       int max = 8; 
       Random random = new Random(); 
       int d = random.nextInt(max - min + 1) + min; 
       Log.d("random ", String.valueOf(d)); 

       mHandler.postDelayed(this, d * 1000); 

      } 

     }, 100); 
+0

是那里的“阵列”里面什么? –

+2

你想显示敬酒消息数组中的每个项目?我不知道这个数组有多大,但是会有大量的Toast消息。也可以使用像不服'Arrays.toString(阵列)',以显示一个烤面包消息中的孔阵列 – ZeusNet

回答

0

您可以通过在Android的使用
Toast.LENGTH_LONG和Toast.LENGTH_SHORT默认指定吐司的持续时间。

但是Toast.LENGTH_LONG持续时间是1500毫秒(1.5秒)
和Toast.LENGTH_SHORT持续时间是3000毫秒(3秒)

千毫秒= 1秒。

你可以使用一些替代它们。
5000.5秒,
1000 1秒,
1500 1.5秒,
2000 2秒,
2500 2.5秒,
3000来回3秒,
或多个
3500对于3.5秒
如你所愿。