Can you give me an example of setOnTouchListener in C#?
I tried like this but I bring some errors.
Button1.setOnTouchListener(new View.OnTouchListener()
{
public boolean onTouch(View arg0, MotionEvent arg1)
{
x.Text = "1";
}
});
Best Solution
You either a. use the
Touch
event:Or you can explicitly implement the
IOnTouchListener
interface (C# does not have anonymous classes). Note that when implementing Java interfaces, you also need to inherit fromJava.Lang.Object
as we need a handle to the Java side of the story (this is obviously not needed when we use theTouch
event).Then set it with:
Note using the latter approach also needs you to handle passing of references to objects that you want to modify in your
OnTouchListener
class, this is not needed with the C# Event.EDIT: As a side note, if you use the
Touch
event or any other event, please remember to be a good citizen and unhook the event when you are not interested in receiving it anymore. Worst case, if you forget to unhook the event, you will leak memory because the instance cannot be cleaned up.So in the first example, don't use a anonymous method:
And remember to unhook it: