0

I have a checkbox with a custom image for the button. I used the click delegate to perform an action whenever the button is clicked:

box.Click += { //do some stuff... }

This is working great.

However, now I have been given the requirement to add swipe detection to this checkbox (Sounds crazy but it does actually make sense for this app).

I added the swipe detection using the standard methods I am used to with normal Android in Java: I subclassed GestureDetector.SimpleOnGestureListener and also implemented View.IOnTouchListener.

I added the swipe detection to the checkbox as follows:

/*
SwipeListener implements View.IOnTouchListener
SwipeDetector is a subclass of GestureDetector.SimpleOnGestureListener
*/

SwipeListener listener = new SwipeListener(new GestureDetector(new SwipeDetector(this)));
box.SetOnTouchListener(listener);

When I do this, the swipe works great. But the click delegate no longer gets activated. I tried moving my code for the click to my SwipeDetector class, and that seemed to work.

But then I noticed that my checkbox was no longer getting its checked/unchecked state and so my custom image for it never changed.

I know this has got to be something simple, but I'm not seeing it... What is the proper way to have a click and a swipe on a view (checkbox) in Android/MonoDroid?

Justin
  • 6,564
  • 6
  • 37
  • 34

1 Answers1

0

My guess without seeing your code is that you are returning true from OnTouch, meaning you have consumed the event and do not wish any further processing to occur using the event. Try returning false if you want the rest of the event to fire.

http://developer.android.com/reference/android/view/View.OnTouchListener.html

jpobst
  • 9,982
  • 1
  • 29
  • 33
  • I'm pretty sure I've already tried that but I can't remember... I'll look at it today and let you know if that changes anything – Justin Jan 04 '12 at 13:35