1

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?

Olias
  • 401
  • 5
  • 17

1 Answers1

1

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
    }
}
Noires
  • 643
  • 8
  • 19
  • Do you have an Example for "Your IOnClicked Implementation"? – Olias Sep 01 '17 at 11:50
  • Updated. Another option might be to adjust the HorizontalPicker class or to re-map it in the binding library, but iam not sure how to do that there. – Noires Sep 01 '17 at 12:05
  • internal class Clicker : Java.Lang.Object, HorizontalPicker.IOnItemClicked { private HorizontalPicker.IOnItemClicked _onItemClickedImplementation; public void OnItemClicked(int p0) { MessageBus.Default.Post("1"); } } – Olias Sep 01 '17 at 12:24