I have a button, I press it and continue to holding it, if holding time exceeds certain time interval it fires some kind of intent, how can i do this. Thanks
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I got an Exception when I used a Timer! You can also use a Handler like below -
Detect
[ACTION_DOWN][1]
and[ACTION_UP][2]
events.When button is pressed (
[ACTION_DOWN][1]
), start timer, measure time... If timer exceeds, invoke Intent. When button is released ([ACTION_UP][2]
) stop timer.When button will be pressed, timer will be started. If button will be released before 5 seconds timeout, nothing will happen, otherwise your desired action will be executed.
try this
You can use
Touch Listener
to do this.Try:
Where
b
is theview
(in your case it should button) on which you want to make long click.And
Runnable
run
is as followsHope it will help... :)
Edit.
Apparently, I have misunderstood the question. Please see @Hardik and @Lunar solutions above.
You could get away with doing something like this:
You can override onTouchEvent and calculate the offset between
ACTION_DOWN
andACTION_UP
;Code below will run a runnable after x amount of time and also remove it if
ACTION_UP
is called before x time. Also included how you can get an exact time value...