进阶_计时器(postDelayed实现)_150503
来源:互联网 发布:淘宝如何做爆款 编辑:程序博客网 时间:2024/05/20 06:26
这次就是上一篇的代码补充,以PostDelay实现计时器,采用了递归的算法
布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="fatenliyer.f_timerone.MainActivity" > <TextView android:id="@+id/tv_one" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textSize="40sp" > </TextView></RelativeLayout>
MainActivity
package fatenliyer.f_timerone;import android.os.Bundle;import android.os.Handler;import android.support.v7.app.ActionBarActivity;import android.widget.TextView;/** * 计时器, 使用postDelayed实现, 一个递归算法 * 个人不喜欢 */public class MainActivity extends ActionBarActivity {private TextView tvShow; private int i = 0; private int TIME = 1000; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvShow = (TextView) findViewById(R.id.tv_one); handler.postDelayed(runnable, TIME); //每隔1s执行 一个典型的递归算法} Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override public void run() { // handler自带方法实现定时器 try { handler.postDelayed(runnable, TIME); tvShow.setText(Integer.toString(i++)); System.out.println("do..."); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("exception..."); } } }; }
代码下载:
http://download.csdn.net/detail/u014803950/8656227
0 0
- 进阶_计时器(postDelayed实现)_150503
- 进阶_计时器(Handler+Thread实现)_150503
- 进阶_计时器(Handler+TimerTask实现)_150503
- Android使用Handler+postDelayed实现简单计时器
- 286_实现计时器功能
- Android中三种计时器Timer、CountDownTimer、handler.postDelayed的使用
- android postDelayed方法实现定时器
- 98_定时器,计时器
- cocos2d_x_04_计时器_数据存储
- 5.10.2_动画计时器
- JavaScript实现的计时器和倒计时器
- 一次性计时器和间隔性计时器实现永久性计时器
- VB实现计时器
- 一个计时器的实现
- AT89C52实现的计时器
- java秒表/计时器实现
- Qt Creator计时器实现
- ACE_Reactor实现计时器
- 欢迎使用CSDN-markdown编辑器
- 对于framework的目录结构分析以及简单的添加一个java层服务
- PV、UV、IP分别是什么意思?
- 新版格式化输出调试信息
- <PY><OOP>PyQt和QtDesigner混合使用(一)伯努利试验
- 进阶_计时器(postDelayed实现)_150503
- HDU ACM 1698 Just a Hook->线段树+区间修改
- PhpMyAdmin mbstring missing
- 黑马程序员_Java语言_面向对象__
- [Apio2011]方格染色
- [POJ] 2084 -> Game of Connections
- DownloadManager功能介绍
- [Unity插件]Behavior Designer:节点
- c++之超越c的语法03-变量初始化