我可以用吐司的CountDownTimer [英] Can I use a Toast for the CountDownTimer

查看:210
本文介绍了我可以用吐司的CountDownTimer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用CountdownTimer内敬酒,但问题是吐司计数太慢,当新的活动恒星的吐司没有完成counting.I知道它是更容易使用一个TextView,但我只是想知道这是possible.Any想法?

  @覆盖
公共无效的onClick(查看为arg0){
    // TODO自动生成方法存根
    如果(Edt.getText()。的toString()。长度()== 0){
        Toast.makeText(MainActivity.this,什么,兄弟?Toast.LENGTH_LONG).show();
    }否则如果(sec.getText()。的toString()。长度()== 0){
        Toast.makeText(MainActivity.this,当,兄弟?Toast.LENGTH_LONG).show();    }其他{
    事件=新的String(Edt.getText()的toString());
    最终诠释时间=的Integer.parseInt(sec.getText()的toString());
    意图敏=新意图(MainActivity.this,Receiver.class);    myInt.putExtra(钥匙,事件);
    的PendingIntent的PendingIntent = PendingIntent.getActivity(MainActivity.this,2敏,PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager AM =(AlarmManager)getSystemService(ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis的()+(时间* 1000),的PendingIntent);
    新CountDownTimer(时间* 1000,1000){         公共无效onTick(长millisUntilFinished){            Toast.makeText(MainActivity.this,报警开始于+ + millisUntilFinished / 1000 +秒,Toast.LENGTH_SHORT).show();         }         公共无效onFinish(){
         }
      }。开始();
}


解决方案

如果你的意思是他们堆叠起来造成的延迟,那么你应该呈现出新之前取消了之前敬酒。

如果你想要的东西更看中你可以尝试使用PopupWindow而不是要显示倒计时,有你有布局等更自由。

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

I want to use a Toast inside the CountdownTimer, but the problem is the Toast counts too slow and when the new Activity stars the Toast isn't finished counting.I know it is easier to use a TextView but I just wanted to know if it is possible.Any ideas?

@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
    if(Edt.getText().toString().length() == 0){
        Toast.makeText(MainActivity.this,"What, bro?",Toast.LENGTH_LONG).show();
    }else if(sec.getText().toString().length() == 0){
        Toast.makeText(MainActivity.this,"When, bro?",Toast.LENGTH_LONG).show();

    }else{
    Event=new String(Edt.getText().toString());
    final int time = Integer.parseInt(sec.getText().toString());


    Intent myInt = new Intent(MainActivity.this,Receiver.class);

    myInt.putExtra("key",Event);
    PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,2,myInt,PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+(time*1000),pendingIntent);


    new CountDownTimer(time*1000, 1000) {

         public void onTick(long millisUntilFinished) {

            Toast.makeText(MainActivity.this,"Alarm starts in"+ +millisUntilFinished/1000 + "seconds",Toast.LENGTH_SHORT).show();

         }

         public void onFinish() {


         }
      }.start();


}

解决方案

If you mean that they stack up causing a delay then you should cancel the prior toast before showing a new one.

If you want something more fancy you could try using a PopupWindow instead to show the countdown, there you have more freedom for layout etc.

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

这篇关于我可以用吐司的CountDownTimer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆