2016-03-10 101 views

回答

2

在xamarin官方網站上有關於這個主題的神文件Android Callable Wrappers 要記住的主要事情是子類Java.Lang.Object

我也做了我自己的包裝,以便我可以在代碼中使用代理重用它。

public class OnItemClickListener : Object, AdapterView.IOnItemClickListener{ 
     public delegate void ItemClick(AdapterView parent, View view, int position, long id); 

     public OnItemClickListener(ItemClick itemClickDelegate){ 
      ItemClickDelegate = itemClickDelegate; 
     } 

     public ItemClick ItemClickDelegate { get; } 

     public void OnItemClick(AdapterView parent, View view, int position, long id){ 
      ItemClickDelegate(parent, view, position, id); 
     } 
    } 

與用法:

new CallbackWrapers.OnItemClickListener(
       delegate (AdapterView parent, View view1, int position, long id) { 
        //Do your stuff 
       }));