我想在CountdownTimer中使用Toast,但问题是Toast计数太慢,当新的Activity星星Toast没有完成计数时。我知道使用TextView更容易,但我只是想知道是否有可能。任何想法?
@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();
}
答案 0 :(得分:0)
如果你的意思是他们堆积起来导致延迟,那么你应该在显示一个新的吐司之前取消之前的吐司。
如果你想要一些更有趣的东西,你可以尝试使用PopupWindow来显示倒计时,那么你有更多的布局等自由。
http://developer.android.com/reference/android/widget/PopupWindow.html