重复只要按钮pressed行动 [英] Repeat an action as long button is pressed

查看:137
本文介绍了重复只要按钮pressed行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设你有一个的TextView 显示像0的号码,你有一个按钮。 现在,如果用户presses按钮在TextView的数量将增加一(这我知道该怎么做),但如果用户presses按钮,然后不松开,那么数字在的TextView 应增加一本只要用户应该重复它自身不松开按钮。 换句话说:如何增加数了一遍又一遍,只要用户按住按钮

Let's say you have a TextView that displays an number like 0 and you have a Button. Now if the user presses the Button the Number in the TextView will increase for one (this i know how to do) but if the user presses the Button and don't release it then the number in the TextView should be increased an this should repeat it self as long the user don't release the Button. In other words: How to increase the Number over and over again as long the user holds down the Button?

推荐答案

一个通用的方法(而不是具体到Android)将检测preSS并分别释放事件。在preSS事件开始周期性任务(的Runnable ),这更增加了计数器(让我们说第二,或每200毫秒一次的5倍)。释放事件停止周期性任务。

A general approach (not specific to Android) would be to detect the press and release event separately. The press event starts a periodic task (Runnable or Thread) which adds to the counter (let us say 5 times a second, or once every 200 ms). The release event stops the periodic task.

这篇关于重复只要按钮pressed行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆