展开全部
package yzy.yyy.yy;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;
public class TimeToast extends Activity {
int i = 60;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what < 0) {
dialog.dismiss();
timer.cancel();
}
dialog.setMessage(msg.what + "");
}
};
AlertDialog dialog = null;
Timer timer = new Timer();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ttt);
dialog = new AlertDialog.Builder(this).setMessage("").create();
dialog.show();
timer.schedule(new TimerTask() {
@Override
public void run() {
Message msg = handler.obtainMessage();
msg.what = i;
handler.sendEmptyMessage(msg.what);
i = i - 1;
}
}, 1000, 1000);
}
@Override
protected void onDestroy() {
super.onDestroy();
if (timer!=null) {
timer.cancel();
timer=null;
}
}
}
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;
public class TimeToast extends Activity {
int i = 60;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what < 0) {
dialog.dismiss();
timer.cancel();
}
dialog.setMessage(msg.what + "");
}
};
AlertDialog dialog = null;
Timer timer = new Timer();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ttt);
dialog = new AlertDialog.Builder(this).setMessage("").create();
dialog.show();
timer.schedule(new TimerTask() {
@Override
public void run() {
Message msg = handler.obtainMessage();
msg.what = i;
handler.sendEmptyMessage(msg.what);
i = i - 1;
}
}, 1000, 1000);
}
@Override
protected void onDestroy() {
super.onDestroy();
if (timer!=null) {
timer.cancel();
timer=null;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询