android repeat action on pressing and holding a button

后端 未结 6 1870
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 04:09

I want to implement repeat action on pressing and holding a button. Example: When user click on a button and hold it,it should call a similar method again and again on a fix

6条回答
  •  情书的邮戳
    2020-11-30 04:46

    Although not a great idea. It could be accomplished by starting a timer on onKeyDown to fire at an interval during which you move the cursor one step and restart the timer. You could then cancel the timer on the onKeyUp event. The way this works on other systems is to typically to move on the first key down then wait a bit to ensure that the user is definitly holding the button... then the repeat can be a bit faster. Think of a keyboard auto repeating. This should work and should not affect the ui thread adversely.

提交回复
热议问题