Thank you very much. It works fine.
On Mar 31, 10:14 am, Streets Of Boston <[email protected]> wrote: > Override you dispatchTouchEvent(...), as you do right now, and forward > its MotionEvent to a GestureDetector you created. > > public class MyView ....{ > > GestureDetector mGD = new GestureDetector(this); > > public MyView(...) { > ... > ... > mGD.setIsLongPressEnabled(true); > ... > } > public boolean dispatchTouchEvent(MotionEvent event) { > ... you may want to handle the MotionEvent.ACTION_UP yourself > first. ... > ... but always call this at the end: > return mGD.onTouchEvent(event); > } > > // Called by the GestureDetector mGD. > public void onLongPress(MotionEvent event) { > // do your stuff here. > } > > } > > On Mar 30, 9:51 pm, Oceanedge <[email protected]> wrote: > > > Thank you very much! > > > But my current usecase is not to detect motion, but hold. I have a > > PhotoView which display an icon. It needs to respond to click and hold > > event. > > If user click on it, it will scroll other widget content in one step. > > If user touch & hold on it, it will scroll the widget content one by > > one continually in about 800ms interval. > > > Currently I implement the behavior by setOnClickListener() method for > > the click event. > > For touch & hold, I override dispatchTouchEvent() method and check for > > the holding status by checking the move shall be less than 10 pixels > > and event.getEventTime() - event.getDownTime() > 800ms for > > MotionEvent.ACTION_MOVE event. > > > It works fine in G1 but not work in emulator. > > Is there any better solution? > > Thanks! > > > On Mar 30, 11:17 am, Romain Guy <[email protected]> wrote: > > > > They work the same. > > > > > I have a class inherited from RelativeLayout and override public > > > > booleandispatchTouchEvent(MotionEvent event) method. After I touch & > > > > hold on the touch screen, in emulator I got MotionEvent.ACTION_DOWN > > > > event only. But in G1, I got MotionEvent.ACTION_DOWN first and then > > > > MotionEvent.ACTION_MOVE continuously, even if I try my best to hold > > > > still my finger tip. > > > > That's simply because you cannot hold your finger still. With a mouse > > > cursor you have a 1px precision, with a finger, it's a lot more. The > > > way to "work around" this is simply to use thresholds when you try to > > > detect motion. For instance in a ScrollView or ListView a scroll > > > happens only if the finger has moved by 16 pixels or more. You can use > > > the same values as the framework by looking at the ViewConfiguration > > > class. > > > > -- > > > Romain Guy > > > Android framework engineer > > > [email protected] > > > > Note: please don't send private questions to me, as I don't have time > > > to provide private support. All such questions should be posted on > > > public forums, where I and others can see and answer them- Hide quoted > > > text - > > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

