Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set onclick listener in xamarin?

I'm quite new to C# and Xamarin and have been trying to implement a bottom sheet element and don't know how to correctly do it. I am using Cocosw.BottomSheet-Xamarin.Android library.

Here is my code:

Cocosw.BottomSheetActions.BottomSheet.Builder b = new Cocosw.BottomSheetActions.BottomSheet.Builder (this);
b.Title ("New");
b.Sheet (Resource.Layout.menu_bottom_sheet)

Now i think i should use b.Listener(...), but it requires an interface IDialogInterfaceOnClickListener as a paramater and i don't know how to do it in C# correctly.

In Java i could write

button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        // Perform action on click
    }
});

I tried doing this:

class BottomSheetActions : IDialogInterfaceOnClickListener {
    public void OnClick (IDialogInterface dialog, int which) {
        Console.WriteLine ("Hello fox");
    }

    public IntPtr Handle { get; }

    public void Dispose() {

    }
}

and then this:

b.Listener (new BottomSheetActions());

But it didnt work.

like image 488
Artūrs Eimanis Avatar asked Feb 04 '16 16:02

Artūrs Eimanis


1 Answers

Use click event instead.

button.Click += delegate 
{
    //Your code
};

See my other answer for more info

like image 121
Let'sRefactor Avatar answered Oct 10 '22 17:10

Let'sRefactor