Bug 1854 - View.IOnTouchListener Being Ignored
Summary: View.IOnTouchListener Being Ignored
Status: RESOLVED INVALID
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 1.9.2
Hardware: PC Windows
: Highest normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-11-03 09:37 UTC by Eric Malamisura
Modified: 2011-12-01 14:38 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Attached an Example where the issue is Isolated (225.99 KB, application/octet-stream)
2011-11-06 15:09 UTC, Eric Malamisura
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Eric Malamisura 2011-11-03 09:37:45 UTC
In 1.2 I have several ImageButtons that I have created custom touch listeners for by inheriting from View.IOnTouchListener, I then instantiate an instance of this class, pass it into SetOnTouchListener, I do all of this on the OnCreate call in the Activity.

I haven't had a chance to pull out this behavior into an empty project and isolate the issue, but when I reverted back to 1.2 and made no code changes it all started working again.  The TouchListener OnTouch event never fires, I set a breakpoint on it and at no point does it drop into this code.  It seems to ignore it completely...

Thanks,
Eric
Comment 1 Jonathan Pryor 2011-11-03 10:14:57 UTC
Could I please get a sample for testing? Writing reproduction code greatly slows things down, and is time better spent investigating and fixing the dozens of other filed bugs... :-)

What I do have is a test which does:

	var textview = new TextView (this);
	textview.Touch += OnTouch;
	SetContentView (textview);

and my OnTouch method is invoked.

Thanks,
 - Jon
Comment 2 Eric Malamisura 2011-11-03 10:39:26 UTC
Ok I will get a sample to you when I get a chance to isolate the issue...
Comment 3 Eric Malamisura 2011-11-06 15:09:46 UTC
Created attachment 832 [details]
Attached an Example where the issue is Isolated

The example attached is very simple, it uses a ImageButton, attaches a View.IOnTouchListener which fires off a couple ToastMessages.  I would encourage you to run it using 1.2 first to see correct behavior, and then run it in 1.9.2 to see incorrect behavior (does nothing).

Thanks,
Eric
Comment 4 Jonathan Pryor 2011-12-01 14:38:51 UTC
I don't know why it even worked in 1.2, but it certainly shouldn't have. :-)

When implementing IJavaObject, you must inherit Java.Lang.Object:

    http://androidapi.xamarin.com/?link=T:Android.Runtime.IJavaObject
    http://docs.xamarin.com/android/advanced_topics/architecture/android_callable_wrappers

If we fix MyTouchListener to inherit from Java.Lang.Object, the sample works:


public class MyTouchListener : Java.Lang.Object, View.IOnTouchListener
{
    public event EventHandler<EventArgs> OnClick;

    Context context;
    public MyTouchListener(Context ctx)
    {
        context = ctx;
    }

    public bool OnTouch(View v, MotionEvent e)
    {
        switch (e.Action)
        {
            case MotionEventActions.Down:
                Toast.MakeText(context, "Down", ToastLength.Short).Show();
                return true;
            case MotionEventActions.Up:
                Toast.MakeText(context, "Up", ToastLength.Short).Show();
                Clicked();
                return true;
            default:
                return false;
        }
    }

    private void Clicked()
    {
        if(OnClick != null)
            OnClick(this, EventArgs.Empty);
    }
}