androidL如何重置计时器(androidL how to reset a timer)
我正在学习使用计时器,并按照http://examples.javacodegeeks.com/android/core/os/handler/android-timer-example/中的示例进行操作。
我希望以一种方式实现,当用户按下按钮时计时器将启动,当用户的手关闭时停止,所以我编码如下:
代码:
button_right.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent event) { if(event.getAction()==MotionEvent.ACTION_DOWN ) { startTime = SystemClock.uptimeMillis(); customHandler.postDelayed(updateTimerThread, 0); if((event.getAction()==MotionEvent.ACTION_UP || event.getAction()==MotionEvent.ACTION_CANCEL)) { timeSwapBuff += timeInMilliseconds; customHandler.removeCallbacks(updateTimerThread); } return false; } }); // setting timer private Runnable updateTimerThread = new Runnable() { public void run() { timeInMilliseconds = SystemClock.uptimeMillis() - startTime; updatedTime = timeSwapBuff + timeInMilliseconds; int secs = (int) (updatedTime / 1000); int mins = secs / 60; secs = secs % 60; int milliseconds = (int) (updatedTime % 1000); tv_timing.setText("" + mins + ":" + String.format("%02d", secs) + ":" + String.format("%03d", milliseconds)); customHandler.postDelayed(this, 0); } };
问题:
一切正常,定时器将在用户按下按钮时启动,在保持时保持运行并在手动关闭时停止。 然而,我发现当用户再次按下按钮时,计时器从上次停止的位置开始,而不是在计算时间之前重置为0。
如果使用此代码,如何修改以使计时器重置为0,以便在再次按下按钮时重新计数? 谢谢!!
I am learning to use a timer, and follow the example in http://examples.javacodegeeks.com/android/core/os/handler/android-timer-example/.
I would like to implement in a way that the timer will start off when the user is pressing the button and stop when the user's hand is off, so I have coded as follows:
Codes:
button_right.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent event) { if(event.getAction()==MotionEvent.ACTION_DOWN ) { startTime = SystemClock.uptimeMillis(); customHandler.postDelayed(updateTimerThread, 0); if((event.getAction()==MotionEvent.ACTION_UP || event.getAction()==MotionEvent.ACTION_CANCEL)) { timeSwapBuff += timeInMilliseconds; customHandler.removeCallbacks(updateTimerThread); } return false; } }); // setting timer private Runnable updateTimerThread = new Runnable() { public void run() { timeInMilliseconds = SystemClock.uptimeMillis() - startTime; updatedTime = timeSwapBuff + timeInMilliseconds; int secs = (int) (updatedTime / 1000); int mins = secs / 60; secs = secs % 60; int milliseconds = (int) (updatedTime % 1000); tv_timing.setText("" + mins + ":" + String.format("%02d", secs) + ":" + String.format("%03d", milliseconds)); customHandler.postDelayed(this, 0); } };
Questions:
Everything works fine, and the timer will start when the user presses the button, keep running when holding and stop when hand is off. Yet I discover that when the user presses the button again, the timer start off from where it stops last time instead of resetting to 0 before counting time.
If using this code, how could it be modified such that the timer is reset to 0 so as to count all over again when the button is being pressed again? Thanks!!
原文:https://stackoverflow.com/questions/19211581
最满意答案
您尝试以错误的方式尝试操作创建帐户和注册日期,而不是仅为正常日期字段添加过滤器,并将这些字段放在工作表中并查看结果。
如果你真的想创建一个过滤器,那么你不能只使用普通过滤器来添加条件,而需要创建一个两个参数。
开始日期的一个参数
结束日期的一个参数
对于这两个参数使用日期字段来显示数据列表
现在创建两个calcualted字段
If create account date >=[start date parameter] and create account date < [end date parameter] then your field end
同样
If registration date >=[start date parameter] and registration date < [end date parameter] then your field end
使用行中的两个文件并将其放置在工作表的列中
You are trying in a wrong way don't try to manipulate create account and registration date instead add a filter only for normal date field and place the fields in sheet and see the result.
If you really want to create a filter then you can't add the condition just using normal filter instead you need to create a two parameters.
One parameter for start date
One parameter for end date
For both the parameters use date field to display the list of data
Now create two calcualted fields
If create account date >=[start date parameter] and create account date < [end date parameter] then your field end
Similarly
If registration date >=[start date parameter] and registration date < [end date parameter] then your field end
USe both the fileds in rows and place date in column of sheet
相关问答
更多-
不太确定这是否会有所帮助,但我遇到了类似的问题,并提出以下(+注释): 我认为你真的必须索引日期字段。 在查询/过滤等方面没有任何其他意义。 在Lucene.net v2.9中,与v2.9相比,有很多术语的范围查询似乎非常慢 通过切换到使用数字字段和数字字段查询,我在使用日期字段时修复了速度问题。 这实际上比我的Lucene.net v2.4基线提高了速度。 在缓存包装器过滤器中包装您的查询意味着您可以挂起为过滤器设置的文档位。 这也将大大加快使用相同过滤器的后续查询。 过滤器在一组查询结果的评分中不起作用 ...
-
dstore过滤日期范围(dstore filter date range)[2022-04-24]
您可以通过使用dojo/store 查询过滤器实现此目的,使用回调函数进行精确查询以管理比较日期 并使用dojo/date compare功能将emplist数组的日期与特定日期进行比较,如下所示: this.employeeStore = new Memory({data: someData}); var compareDate = new Date(2014,1,1); var results = store.query(function(object){ // compare return ... -
您尝试以错误的方式尝试操作创建帐户和注册日期,而不是仅为正常日期字段添加过滤器,并将这些字段放在工作表中并查看结果。 如果你真的想创建一个过滤器,那么你不能只使用普通过滤器来添加条件,而需要创建一个两个参数。 开始日期的一个参数 结束日期的一个参数 对于这两个参数使用日期字段来显示数据列表 现在创建两个calcualted字段 If create account date >=[start date parameter] and create account date < [end date paramet ...
-
唯一的方法是使用bool/should查询来捕获这个约束 要么没有AvailableUntil日期 或者AvailableUntil比今天晚 该查询将如下所示: var baseQuery = { "size": 1000, "query": { "bool": { "minimum_should_match": 1, "should": [ { "bool": { ...
-
Datatables日期范围过滤器(Datatables date range filter)[2022-06-20]
我通过https://www.datatables.net/examples/plug-ins/range_filtering.html获得了我的工作基地。 这是我的jsfiddle https://jsfiddle.net/bindrid/2bkbx2y3/6/ $(document).ready(function () { $.fn.dataTable.ext.search.push( function (settings, data, dataIndex) { ... -
要查找在另一个表中不匹配的行,可以使用LEFT JOIN/NULL模式。 使用LEFT JOIN ,子表上的条件将放入ON子句中。 父表上的条件放入WHERE子句中。 SELECT p.* FROM property_tbl AS p LEFT JOIN booking_tbl AS b ON p.id = b.propertyID AND booking_tbl.endDate > '17-10-24' AND booking_tbl.startDate < '17-10-31' WHERE b.prop ...
-
我认为你不需要自定义搜索引擎。 您可以过滤交叉关联。 这应该适合你: filter :surveys_updated_at, label: 'By Date Completed', as: :date_range 你做的不是,一个洗劫者应该如何工作。 我知道这是一个常见的谷歌结果,但这是错误的。 在ActiveAdmin中,搜索者不会立即收到这两个日期。 搜索者将使用by_date_completed_gteq和by_date_completed_lteq 。 ransacker格式化程序仅用于格式化输入 ...
-
要编辑,请使用dataTable语言扩展名。 在构造函数中添加此行。 "language": { "infoFiltered": "" }, 资源 In order to edit, use dataTable language extension. Add this line on your constructor. "language": { "infoFiltered": "" } ...
-
我不明白为什么要反转数据表中的行。 从我的角度来看,这不是必要的。 您可以使用Linq查询过滤行,如下所示: private DataTable FilterTable(DataTable table, DateTime startDate, DateTime endDate) { var filteredRows = from row in table.Rows.OfType
() where (DateTime) row[0] >= startDa ... -
我也遇到了这个任务,经过几个小时的尝试终于解决了它:)。 您需要使用媒体商店并查询它从日期和日期传递的时间长,这将返回一个位图数组以下是适合我的代码。 final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID, MediaStore.Images.Media.DATE_TAKEN, MediaStore ...