Detecting long touch press (ACTION_DOWN only)??

by eminemence » Thu, 02 Sep 2010 01:55:07 GMT


Sponsored Links
 Hi,
I want to figure out how to detect that the user has been doing a long
touch press on the screen?
Most of the solutions that I see assume that the DOWN + UP sequence of
events.
Thanks in advance.

--



Detecting long touch press (ACTION_DOWN only)??

by fr4gus » Thu, 02 Sep 2010 02:22:06 GMT


 If you don't have a requirement about how long should be the time to
trigger a long press, you could use

android.view.GestureDetector;

android.view.GestureDetector.SimpleOnGestureListener;

If you need to detect a long in a specific View object, what I do is
to register a OnTouchListener in my View object, that will redirect
the MotioEvent to the GestureDetector. At this point I'm able to
record what View was touched, and keep it in a variable of my current
Activity. Then in the gesture listener I took this variable and use
it. But if someone else knows a better approach I would like to hear
it :).

Best,

fr4gus




--


Sponsored Links


Other Threads

1. The app got crashed on SDK 1.5 which is working fine on SDK 1.0

Hi friends,

I have developed an application which has tabActivity using SDK 1.0
r2.

1st Tab contains List view. -> the list contains some images

2nd and 3rd contains some webviews.

The app works fine on G1 mobile.

Today I downloaded SDK 1.5 and ran the same app on SDK 1.5.

The app got crashed when I scroll down/up the list items very fast
(fling)

I/dalvikvm( 1006): Stack overflow, expanding (0x41048200 to
0x41048000)
I/dalvikvm( 1006): Shrank stack (to 0x41048200, curFrame is
0x41049cd8)
D/AndroidRuntime( 1006): Shutting down VM
W/dalvikvm( 1006): threadid=3: thread exiting with uncaught exception
(group=0x4000fe70)
E/AndroidRuntime( 1006): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime( 1006): java.lang.StackOverflowError
E/AndroidRuntime( 1006):        at android.text.Styled.measureText
(Styled.java:371)
E/AndroidRuntime( 1006):        at android.text.Layout.measureText
(Layout.java:1600)
E/AndroidRuntime( 1006):        at android.text.Layout.getLineMax
(Layout.java:654)
E/AndroidRuntime( 1006):        at android.text.Layout.draw(Layout.java:310)
E/AndroidRuntime( 1006):        at android.text.BoringLayout.draw
(BoringLayout.java:356)
E/AndroidRuntime( 1006):        at android.widget.TextView.onDraw
(TextView.java:3921)
E/AndroidRuntime( 1006):        at android.view.View.draw(View.java:5838)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.drawChild
(ViewGroup.java:1486)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime( 1006):        at android.view.View.buildDrawingCache
(View.java:5615)
E/AndroidRuntime( 1006):        at android.view.View.getDrawingCache
(View.java:5458)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.drawChild
(ViewGroup.java:1422)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime( 1006):        at android.widget.AbsListView.dispatchDraw
(AbsListView.java:1319)
E/AndroidRuntime( 1006):        at android.widget.ListView.dispatchDraw
(ListView.java:2820)
E/AndroidRuntime( 1006):        at android.view.View.draw(View.java:5944)
E/AndroidRuntime( 1006):        at android.widget.AbsListView.draw
(AbsListView.java:2121)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.drawChild
(ViewGroup.java:1486)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.drawChild
(ViewGroup.java:1484)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime( 1006):        at android.view.View.draw(View.java:5944)
E/AndroidRuntime( 1006):        at android.widget.FrameLayout.draw
(FrameLayout.java:352)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.drawChild
(ViewGroup.java:1486)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.drawChild
(ViewGroup.java:1484)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime( 1006):        at android.view.View.draw(View.java:5841)
E/AndroidRuntime( 1006):        at android.widget.FrameLayout.draw
(FrameLayout.java:352)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.drawChild
(ViewGroup.java:1486)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.drawChild
(ViewGroup.java:1484)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.drawChild
(ViewGroup.java:1484)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.drawChild
(ViewGroup.java:1484)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.drawChild
(ViewGroup.java:1484)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime( 1006):        at android.view.View.draw(View.java:5841)
E/AndroidRuntime( 1006):        at android.widget.FrameLayout.draw
(FrameLayout.java:352)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.drawChild
(ViewGroup.java:1486)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.drawChild
(ViewGroup.java:1484)
E/AndroidRuntime( 1006):        at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime( 1006):        at android.view.View.draw(View.java:5841)
E/AndroidRuntime( 1006):        at android.widget.FrameLayout.draw
(FrameLayout.java:352)
E/AndroidRuntime( 1006):        at
com.android.internal.policy.impl.PhoneWindow$DecorView.draw
(PhoneWindow.java:1847)
E/AndroidRuntime( 1006):        at android.view.ViewRoot.draw(ViewRoot.java:
1217)
E/AndroidRuntime( 1006):        at android.view.ViewRoot.performTraversals
(ViewRoot.java:1030)
E/AndroidRuntime( 1006):        at android.view.ViewRoot.handleMessage
(ViewRoot.java:1482)
E/AndroidRuntime( 1006):        at android.os.Handler.dispatchMessage
(Handler.java:99)
E/AndroidRuntime( 1006):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 1006):        at android.app.ActivityThread.main
(ActivityThread.java:3948)
E/AndroidRuntime( 1006):        at java.lang.reflect.Method.invokeNative
(Native Method)
E/AndroidRuntime( 1006):        at java.lang.reflect.Method.invoke
(Method.java:521)
E/AndroidRuntime( 1006):        at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:782)
E/AndroidRuntime( 1006):        at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:540)
E/AndroidRuntime( 1006):        at dalvik.system.NativeStart.main(Native
Method)

I am not understanding the above error log.

Then I experimented some thing like this: I removed the TabActivity,
just shown only list activity. Then I scroll down/up the list items.
Then there is no crash.

Can any one please help me.

Thanks,
manoj.
--~--~---------~--~----~------------~-------~--~----~

2. installing android os

has any1 tried inostallin the android on a pda?
is it always from the source code, or is there any other way???

--~--~---------~--~----~------------~-------~--~----~

3. Problem with Internet connection through emulator

4. view Log on device

5. vertical scrolling TableLayout

6. Problem with Internet connection through emulator

7. Canvas.drawPoint() is faster than Bitmap.setPixel()?