For testing purposes I used setOnCreateContextMenuListener and the context menu still doesn't show. The reason for that is that I'm also catching View.onTouchEvent(MotionEvent event). The documentation for the GestureDetector says: "In the onTouchEvent(MotionEvent) method ensure you call onTouchEvent(MotionEvent). The methods defined in your callback will be executed when the events occur." The first onTouchEvents is a View method the second one a GestureDetector method. I assume that's the piece missing in your code.
Emanuel Moecklin 1gravity LLC On May 4, 10:54 am, Justin Anderson <[email protected]> wrote: > I already am using a GestureDetector... For some reason I couldn't get it to > not show the context menu on long press... But I was using > setOnCreateContextMenuListener(). > > I'll go ahead and give what you suggest a try. I wasn't sure it would work > because registerForContextMenu() says it sets the > onCreateContextMenuListener() and thought I would have the same problem. > > Thanks, > Justin Anderson > MagouyaWare Developerhttp://sites.google.com/site/magouyaware > > On Wed, May 4, 2011 at 7:45 AM, Emanuel Moecklin <[email protected]>wrote: > > > > > > > > > You can use a GestureDetector to listen to motion events one of them > > being onLongPress(MotionEvent e). > > In that method you decide whether you want to show the context menu or > > not. If you decide to show it call activity.openContextMenu(myView); > > (registerForContextMenu (View view) needs to be called before that). > > This way it won't open on a long-press unless you want it to. You can > > use the other GestureListener events to show the context menu e.g. for > > double taps. > > > Here's some sample code: > > > gestureDetector = new GestureDetector(activity, gestureListener); > > gestureDetector.setIsLongpressEnabled(true); > > > private GestureDetector.SimpleOnGestureListener gestureListener = > > new > > GestureDetector.SimpleOnGestureListener() { > > > @Override > > public boolean onSingleTapUp(MotionEvent event) { > > // do something > > return true; > > } > > > @Override > > public boolean onDown(MotionEvent event) { > > // do something > > return true; > > } > > > @Override > > public void onLongPress(MotionEvent event) { > > if (want2ShowContextMenu) { > > activity.openContextMenu(myView.this); > > } > > } > > > @Override > > public boolean onDoubleTap(MotionEvent event) { > > // do something > > return true; > > } > > > }; > > > BTW this is code I use in one of my apps and suppressing the context > > menu works perfectly. > > > Emanuel Moecklin > > 1gravity LLC > > > On May 3, 5:21 pm, Justin Anderson <[email protected]> wrote: > > > *> So you only want it to call the context menu when you call it, not on > > > long press?* > > > > Exactly. But that is only because I have several other actions that can > > be > > > customized by the user... It kind of seems like it would feel unfinished > > if > > > the user could customize what happens for short press, double press, > > swipe > > > up, and swipe down but not long press... > > > > Though the more I think about it the more I'm thinking it's not worth > > it... > > > The default Context Menu behavior would be long-press anyway and I don't > > > know how many people would actually change its behavior were the option > > > there. > > > > *> If that's the case, could you add a long press listener and > > purposefully > > > eat it so it doesn't trigger the context menu? No idea if that would work > > > and would be hacky but ...* > > > * > > > * > > > Yeah I'm not sure if it would work or not either and it does seem > > hackish... > > > I'm thinking I'm just going to leave it as it is unless I get a lot of > > user > > > requests to add customization of the context menu as well. > > > > Thanks, > > > Justin Anderson > > > MagouyaWare Developerhttp://sites.google.com/site/magouyaware > > > > On Tue, May 3, 2011 at 2:17 PM, TreKing <[email protected]> wrote: > > > > On Tue, May 3, 2011 at 3:03 PM, Justin Anderson <[email protected] > > >wrote: > > > > >> And as I stated before, if you > > useView.setOnCreateContextMenuListener() > > > >> then it sets up your view to show the context menu on with a > > long-press... > > > >> And I'm back to square one. > > > > > Yeah, I would expect that, as it's the default behavior. So you only > > want > > > > it to call the context menu when you call it, not on long press? > > > > If that's the case, could you add a long press listener and > > purposefully > > > > eat it so it doesn't trigger the context menu? No idea if that would > > work > > > > and would be hacky but ... > > > --------------------------------------------------------------------------- > > ---------------------- > > > > TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago > > > > transit tracking app for Android-powered devices > > > > > -- > > > > 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 > > > -- > > 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 -- 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

