如何创建计时器? [英] How to create timer?
问题描述
我需要单击单击并双击(用于远程控制),例如当我触摸表面时,计时器启动,再次触摸计时器停止并计算触摸之间的差异(以毫秒为单位)。我用Google搜索,但发现了一个庞大而硬的代码。请帮助..
请检查这个博客,我应该解释一下这个东西: http://steve.odyfamily.com/?p=12 [ ^ ]
如果您想要简单的方法来了解客户端之间双击的时间。
你不需要启动计时器。
就这样做
你会得到你想要的东西。
public class MainActivity extends 活动{
private long fristTime = - 1 跨度>;
@覆盖
受保护 void onCreate(Bundle savedInstanceState){
super .onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.textmain).setOnClickListener( new OnClickListener(){
@Override
public void onClick(查看v){
if (fristTime> 0){
Log.d( 打印, 双击第一次点击到第二次点击,以毫秒为单位: +(System.currentTimeMillis() - fristTime));
fristTime = - 1 ;
}
< span class =code-keyword> else {
fristTime = System.currentTimeMillis();
}
}
});
}
}
----- -------------------------------------------------- ---
顺便说一句。
在纽约找工作。
我有3年关于andorid的经验。
并且在MS 2005服务器C ++中几乎没有关于游戏服务器的经验
。
谢谢。
------------------------------------------------- ---------
I need to separate click and double click(for remote control), for example when I touch surface, timers starts, wheh I touch again timer stops and calculates difference between touches in milliseconds. I googled, but found a large and hard code. Please, help..
Please check this Blog,m that should explain the thingy: http://steve.odyfamily.com/?p=12[^]
If you want the easy way to know the time for the client between to double click .
You don''t need to start a timer .
Just do like this
you will get what you want.
public class MainActivity extends Activity { private long fristTime = -1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.textmain).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(fristTime>0){ Log.d("Print","double click between frist click to second click in milliseconds is : "+(System.currentTimeMillis()-fristTime)); fristTime = -1; } else{ fristTime = System.currentTimeMillis(); } } }); } }
----------------------------------------------------------
by the way.
find a job in New York.
I have 3 year Experience about andorid.
And have few Experience about game server
in MS 2005 server C++.
Thanks.
----------------------------------------------------------
这篇关于如何创建计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!