Handler倒计时
来源:互联网 发布:dns默认端口 编辑:程序博客网 时间:2024/05/17 22:40
package com.example.daojishi;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends Activity {
ImageView iv;
AnimationDrawable ad;
TextView tv;
int time=5;
Handler handler=new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv=(ImageView) findViewById(R.id.iv);
tv=(TextView) findViewById(R.id.tv);
ad=(AnimationDrawable) iv.getBackground();
ad.start();
tv.setText("倒计时:"+time);
handler.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
time--;
handler.postDelayed(this, 1000);
if(time==-1){
Intent intent=new Intent(MainActivity.this, OtherActivity.class);
startActivity(intent);
}else{
tv.setText("倒计时:"+time);
}
}
}, 1000);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
handler.removeCallbacksAndMessages(null);
}
}
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends Activity {
ImageView iv;
AnimationDrawable ad;
TextView tv;
int time=5;
Handler handler=new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv=(ImageView) findViewById(R.id.iv);
tv=(TextView) findViewById(R.id.tv);
ad=(AnimationDrawable) iv.getBackground();
ad.start();
tv.setText("倒计时:"+time);
handler.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
time--;
handler.postDelayed(this, 1000);
if(time==-1){
Intent intent=new Intent(MainActivity.this, OtherActivity.class);
startActivity(intent);
}else{
tv.setText("倒计时:"+time);
}
}
}, 1000);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
handler.removeCallbacksAndMessages(null);
}
}
阅读全文
0 0
- handler倒计时
- Handler倒计时
- Handler倒计时
- Handler倒计时
- Handler实现倒计时
- handler.postDelayed循环倒计时
- handler倒计时跳转页
- 倒计时 Timer和handler
- 安卓倒计时(android.os.Handler.Handler()
- 倒计时功能CountDownTimer PK Handler
- 关于Handler进行倒计时服务
- handler最简单的倒计时
- Handler倒计时跳转1v
- Handler实现验证码获取倒计时功能
- 用Thread和Handler实现倒计时
- 用Handler与Timer实现progressDialog倒计时
- Android中利用Handler做的倒计时
- Andorid启动页倒计时用Handler实现
- MVP&Retrofit&Rxjava&Gson的简单例子
- Codeforces 844C Sorting by Subsequences【思维】
- C语言之continue与break的异同
- VS项目属性的一些配置项的总结
- TensorFlow函数:tf.Session()和tf.Session().as_default()的区别
- Handler倒计时
- C++学习之路 day2
- C++计算逆序对
- 基于socket---简单聊天室的实现
- Different GCD Subarray Query HDU
- 牛客网---2016---京东小东分苹果
- WPF程序性能优化总结
- linux 查看当前路径命令:pwd
- SQL语句练习以及答案 (2)