java翻译到mono C#实现系列(4) 利用CountDownTimer类实现倒计时功能 mono版
群里的朋友问利用CountDownTimer类实现倒计时功能怎么实现,我就百度了,参考http://blog.csdn.net/qq344429461/article/details/7521361写了个mono版的.
本人菜鸟,请各位多多指点,不足之处,请斧正.没啥技术含量,就权当丰富下mono for android的小代码.
using System; using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Java.Util; namespace AndroidApplication5
{
[Activity(Label = "AndroidApplication5", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity
{
private MyCount mc;
private TextView tv; protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
tv = (TextView)FindViewById(Resource.Id.MyButton);
mc = new MyCount(this,, );
mc.Start();
}
public class MyCount : CountDownTimer
{
private Activity context = null;
TextView tv ;
public MyCount(Activity Activity,long millisInFuture, long countDownInterval): base(millisInFuture, countDownInterval)
{
this.context = Activity;
tv = (TextView)context.FindViewById(Resource.Id.MyButton);
}
public override void OnTick(long millisUntilFinished)
{
DateTime date=new DateTime(millisUntilFinished);
String str = date.ToString();
Console.WriteLine(str);
tv.SetText("请等待70秒(" + millisUntilFinished / + ")...", TextView.BufferType.Normal);
}
public override void OnFinish()
{
tv.Text = "finish";
}
}
public override void Finish()
{
base.Finish();
mc.Cancel();
}
}
}
原java版
public class MainActivity extends Activity {
private MyCount mc;
private TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView)findViewById(R.id.show);
mc = new MyCount(70000, 1000);
mc.start();
}
class MyCount extends CountDownTimer{
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
System.out.println("你好");
}
@Override
public void onTick(long millisUntilFinished) {
Date date = new Date(millisUntilFinished);
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
String str = sdf.format(date);
System.out.println(str);
tv.setText("请等待70秒("+millisUntilFinished / 1000 +")...");
}
@Override
public void onFinish() {
tv.setText("finish");
}
}
@Override
protected void onDestroy() {
super.onDestroy();
mc.cancel();
}
}
java翻译到mono C#实现系列(4) 利用CountDownTimer类实现倒计时功能 mono版的更多相关文章
- java从入门到卖肠粉系列
java从入门到卖肠粉系列 注:本教程只是从JAVA基础开始,绝对不会跟公司有任何利益冲突,更不会出现一行公司项目的代码 QQ群:9547527 推荐用土豆,百度去上传太慢,百度云在线播放还要转码.. ...
- Java并发包源码学习系列:阻塞队列BlockingQueue及实现原理分析
目录 本篇要点 什么是阻塞队列 阻塞队列提供的方法 阻塞队列的七种实现 TransferQueue和BlockingQueue的区别 1.ArrayBlockingQueue 2.LinkedBloc ...
- [翻译svg教程]svg学习系列 开篇
目录 [翻译svg教程]svg学习系列 开篇 [翻译svg教程 ]svg 的坐标系统 [翻译svg教程]svg 中的g元素 [翻译svg教程]svg中矩形元素 rect [翻译svg教程]svg中的c ...
- 【java集合框架源码剖析系列】java源码剖析之TreeSet
本博客将从源码的角度带领大家学习TreeSet相关的知识. 一TreeSet类的定义: public class TreeSet<E> extends AbstractSet<E&g ...
- 【java集合框架源码剖析系列】java源码剖析之HashSet
注:博主java集合框架源码剖析系列的源码全部基于JDK1.8.0版本.本博客将从源码角度带领大家学习关于HashSet的知识. 一HashSet的定义: public class HashSet&l ...
- 【java集合框架源码剖析系列】java源码剖析之TreeMap
注:博主java集合框架源码剖析系列的源码全部基于JDK1.8.0版本.本博客将从源码角度带领大家学习关于TreeMap的知识. 一TreeMap的定义: public class TreeMap&l ...
- 【java集合框架源码剖析系列】java源码剖析之ArrayList
注:博主java集合框架源码剖析系列的源码全部基于JDK1.8.0版本. 本博客将从源码角度带领大家学习关于ArrayList的知识. 一ArrayList类的定义: public class Arr ...
- 【java集合框架源码剖析系列】java源码剖析之LinkedList
注:博主java集合框架源码剖析系列的源码全部基于JDK1.8.0版本. 在实际项目中LinkedList也是使用频率非常高的一种集合,本博客将从源码角度带领大家学习关于LinkedList的知识. ...
- 【java集合框架源码剖析系列】java源码剖析之HashMap
前言:之所以打算写java集合框架源码剖析系列博客是因为自己反思了一下阿里内推一面的失败(估计没过,因为写此博客已距阿里巴巴一面一个星期),当时面试完之后感觉自己回答的挺好的,而且据面试官最后说的这几 ...
随机推荐
- struct 和union的区别
union ( 共用体):构造数据类型,也叫联合体 用途:使几个不同类型的变量共占一段内存(相互覆盖) struct ( 结构体 ):是一种构造类型 用途: 把不同的数据组合成一个整体——自定义数据 ...
- PHP中刷新输出缓冲详解[转载]
PHP中刷新输出缓冲详解 分类: PHP Web开发2011-07-23 17:42 1795人阅读 评论(0) 收藏 举报 phpbuffer浏览器outputapache模块脚本 buffer是一 ...
- alertView 上添加textField
- (void)showTextFieldUIAlertView { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@ ...
- 搭建简易Web GIS网站:使用GeoServer+PostgreSQL+PostGIS+OpenLayers3
Web GIS系列: 搭建简易Web GIS网站:使用GeoServer+PostgreSQL+PostGIS+OpenLayers3 使用GeoServer+QGIS发布WMTS服务 使用GeoSe ...
- intrinsicConditionQueue笔记
一, 使用conditionQueue需要注意的一些点: 一个conditionQueue被多种Predicate condition 使用是很正常的,所以当一个wait的线程被唤醒的时候,很有可能它 ...
- 疯狂JAVA讲义---第十五章:输入输出(上)流的处理和文件
在Java中,把这些不同类型的输入.输出抽象为流(Stream),而其中输入或输出的数据称为数据流(Data Stream),用统一的接口来表示,从而使程序设计简单明了. 首先我要声明下:所谓的输入输 ...
- Navicet Mysql数据库电脑本地备份
Navicet Mysql数据库电脑本地备份 1.打开navicat客户端,连上mysql后,双击左边你想要备份的数据库.点击"计划",再点击"新建批处理作业" ...
- eclipse mac
在mac下安装eclipse,挺简单的.只是字体会发虚,有点麻烦. 安装完成后,双击eclipse图标,显示包内容,contents--info.plist,在</dist>前加<k ...
- [翻译]Event Handler Description 事件处理描述
Event Handler Description 事件处理描述 (自定义控件) How should a new event handler be defined if it does not ...
- Python学习-5.Python的变量与数据类型及字符串的分割与连接
在Python中,变量类型是固定的,一旦声明就不能修改其类型(在Python里感觉不应该用声明,而应该用使用) 正确: var = 1 print(var) var = 2 print(var) 依次 ...