[code="java"]
package com.rp;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class TimeCountActivity extends Activity {
private Button btn;
private TextView textView;
Handler handler;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = new TextView(this);
final AlertDialog alertDialog = new AlertDialog.Builder(this)
.setView(textView).setIcon(R.drawable.icon).setTitle("提示")
.setMessage("是否进入下一视频")
.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
}).create();
handler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what > 0) {
Log.v("time", msg.what + "");
textView.setText(msg.what + "秒自动跳转下一首");
} else {
alertDialog.dismiss();
textView.setText("Over......");
}
super.handleMessage(msg);
}
};
btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
alertDialog.setView(textView);
alertDialog.show();
Timer time = new Timer(true);
TimerTask tt = new TimerTask() {
int countTime = 10;
public void run() {
if (countTime > 0) {
countTime--;
}
Message msg = new Message();
msg.what = countTime;
handler.sendMessage(msg);
}
};
time.schedule(tt, 1000, 1000);
}
});
}
}
[/code]