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?

4

1 回答 1

1

看起来,问题在于原始项目,因为它无法为其创建事件委托。您可以通过以下代码使用该事件,并且必须为以下代码编写 IOnClicked 的实现:

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

更新实施:

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

    }

    public IntPtr Handle { get; }
    public void OnItemClicked(int p0)
    {
        // Do something with p0
    }
}
于 2017-09-01T11:42:59.317 回答