Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Analog SetOnTouchListener or how it use in xamarin, what argument must be

I need use SetOnTouchListener:

LinearLayout cardLinearLayout = FindViewById<LinearLayout> (Resource.Layout.CardList);
cardLinearLayout.SetOnTouchListener (this);//Can't use THIS, must be argument  with IOnTouchListener type. Where can I get this argument?

enter image description here

I want use it for ViewFlipper. Maybe other way exists.

like image 478
Olena Avatar asked Dec 26 '22 20:12

Olena


1 Answers

In Xamarin.Android a lot of the Listener interfaces have been converted to events for more of a C# type of code.

So on all Views there is a Touch event which corresponds to the stuff happening in the OnTouchListener.

However, if you really, really want to, you can implement the IOnTouchListener interface like so:

public class MyOnTouchListener : Java.Lang.Object, View.IOnTouchListener
{
    public bool OnTouch(View v, MotionEvent e)
    {
        /* do stuff */
    }
}

And then use it on your LinearLayout like so:

cardLinearLayout.SetOnTouchListener (new MyOnTouchListener());

You can compare that to the Touch event, which only takes one line of code:

cardLinearLayout.Touch += (s, e) => { /* do stuff */ };
like image 166
Cheesebaron Avatar answered Dec 31 '22 12:12

Cheesebaron