我想在 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();
}