简体   繁体   English

按下按钮时如何连续递增值?

[英]how to increment a value continuosly when a button is pressed?

I have a button and a textview with the number 1 displayed when my app is running. 我的应用程序运行时,有一个按钮和一个显示数字1的textview。 When i press and hold the button i want the value to continuosly increment till I let go of the button. 当我按住按钮时,我希望值连续增加,直到我放开按钮为止。 It is very frustrating for me because i used to know how to do this and it was as simple as setting the button properties to something in xml. 这让我感到非常沮丧,因为我曾经知道如何做到这一点,而且就像将按钮属性设置为xml中的内容一样简单。 However I have forgotten how and i have searched through the internet and the examples i have found implement an ontouch listener that only increments the value by one. 但是,我忘记了如何以及如何通过互联网进行搜索,发现的示例实现了一个ontouch侦听器,该侦听器只会将该值加1。 But i want the value to be increment continuosly depending on how long the user presses the button. 但是我希望该值根据用户按下按钮的时间连续增加。 this is not a repeat of Triggering event continuously when Button is pressed down in Android 这不是在Android中按下Button时连续不断地触发事件的重复

Triggering event continuously when Button is pressed down in Android 在Android中按下Button时连续触发事件

as they did not work for me. 因为他们没有为我工作。 so can some remind me how to get a button to increment a value continuosly when you press and hold the button? 所以有人可以提醒我如何在按住按钮时如何使按钮连续增加值吗?

使用onTouchListener并在MotionEvent.ACTION_DOWN和MotionEvent.ACTION_UP上启动/停止计数器例程

Android long-touch event Android长按活动

bramburys answer in the link above worked perfectly whilst other answers incremented one at a time when the button was pressed whilst bramburys incremented continuously. 上面链接中的bramburys答案运行良好,而按下按钮时,其他答案每次增加一个,而bramburys则连续增加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM