Java Event Binding Issue Binding Library

159 Views Asked by At

I transfered this https://github.com/blazsolar/HorizontalPicker Library into Java Binding Library. The Library implements an OnItemSelected Event whicht is used like this in Java.

@Override
public void onItemSelected(int index)    {
    Toast.makeText(this, "Item selected", Toast.LENGTH_SHORT).show();
}

Now i want to use it like this in my C# Code.

var Picker = view.FindViewById<Com.Wefika.Horizontalpicker.HorizontalPicker>(Resource.Id.numberPicker);
Picker.onItemClicked+= delegate{};

Unfortunately onItemClicked does not exist. I looked in the generated api xml and there it is declared.

<interface abstract="true" deprecated="not deprecated" final="false" name="HorizontalPicker.OnItemClicked" static="true" visibility="public">
<method abstract="true" deprecated="not deprecated" final="false" name="onItemClicked" native="false" return="void" static="false" synchronized="false" visibility="public">

Now I´m wondering how i can use this Event? Do i have to modify something or can i get it on a different way?

1

There are 1 best solutions below

3
On BEST ANSWER

How it seems, the issue lies in the original project since it cant create a event delegate for it. You can use the event though with the following code and have to write a implementation for IOnClicked for the following code:

HorizontalPicker Picker = view.FindViewById<Com.Wefika.Horizontalpicker.HorizontalPicker>(Resource.Id.numberPicker);
HorizontalPickerItemClicked itemclicked = new HorizontalPickerItemClicked();
Picker.SetOnItemClickedListener(itemclicked); 

Updated Implementation:

public class HorizontalPickerItemClicked : HorizontalPicker.IOnItemClicked
{
    public void Dispose()
    {

    }

    public IntPtr Handle { get; }
    public void OnItemClicked(int p0)
    {
        // Do something with p0
    }
}