Event when button pressed, held, released?

Put your problem here if it does not fit any of the other categories.

Event when button pressed, held, released?

Postby certron » Fri Feb 22, 2008 12:06 am

I'm trying to get the events when a button is pressed and then again when it is released (and calculate the time between the two events) but I can't find where this is possible. If you are confused what I am asking, imagine pushing the button for a hot air balloon. You can press it for a short time or press it and hold it for a longer time to get more hot air.

I was looking at the pizza timer tutorial, which doesn't have button press and release events, only the direction pad (up, down, left, right) that confused me.

Then I looked at the Button used in the Android notepad tutorials, but that doesn't seem to be what I want, either... I can push and hold the button and it stays pressed, and it becomes un-pressed when I let go, but I want to trigger an event when that happens.

***

Before I post this question, I did notice that there is onKeyUp as well as onKeyDown, but I want to have this for an on-screen button, not for a physical button on the device (not now, at least). Also, I'm not sure if this method will work (but I hope it does).

****
Edit some more: I want to have an event triggered when the on-screen button is pressed (easy) and another event when the button is released. Is this possible? Does this exist already?
Last edited by certron on Sat Feb 23, 2008 5:46 am, edited 1 time in total.
certron
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Jan 29, 2008 4:42 pm

Top

Postby tsucheck » Fri Feb 22, 2008 2:06 am

How about getting current time when the user presses the button and storing it somewhere (eg. bundle, or DB, or whatever). Then when user lets go of the button you get the current time again and calculate the delta. This way you would know how long the button was pressed for.
tsucheck
Developer
Developer
 
Posts: 29
Joined: Sun Feb 17, 2008 2:07 am

Postby certron » Fri Feb 22, 2008 2:35 am

tsucheck wrote:How about getting current time when the user presses the button and storing it somewhere (eg. bundle, or DB, or whatever). Then when user lets go of the button you get the current time again and calculate the delta. This way you would know how long the button was pressed for.


This is exactly what I want to do, however, I want onKeyUp and onKeyDown for the on-screen button. The timekeeping is going to be handled as in this article, A Stich In Time: http://android-developers.blogspot.com/ ... -time.html

I figure I need some kind of button listener, but it seems like there is only events for pushing the button, not releasing it.
certron
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Jan 29, 2008 4:42 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 21 guests