我目前正在 Monodroid 中编程,但我遇到了 Listview 扩展的问题。
我目前的 ListView 扩展如下:
public class TTListView : ListView
{
private Context mContext;
private bool wrapAdapter;
public TTListView(Context context) :
base(context)
{
Initialize();
this.mContext = context;
}
public TTListView(Context context, IAttributeSet attrs) :
base(context, attrs)
{
Initialize();
this.mContext = context;
}
public TTListView(Context context, IAttributeSet attrs, int defStyle) :
base(context, attrs, defStyle)
{
Initialize();
this.mContext = context;
}
private void Initialize()
{
this.CacheColorHint = Color.Transparent;
//Still some more stuff to be added here
}
public void InsertItemAt(int index)
{
Animation anim = AnimationUtils.LoadAnimation(
mContext, Resource.Animator.slide_top_down);
anim.Duration = 500;
this.GetChildAt(index).StartAnimation(anim);
}
public void SetDelegate(TTListDelegate _delegate)
{
this.OnItemClickListener = (IOnItemClickListener)_delegate;
this.OnItemLongClickListener = (IOnItemLongClickListener)_delegate;
}
public override void AddFooterView(View v)
{
base.AddFooterView(v);
wrapAdapter = true;
}
/*public override IListAdapter Adapter
{
get
{
return base.Adapter;
}
set
{
//Check if the passed parameter is a TTListAdapter
TTListAdapter _ttadapter = value as TTListAdapter;
if (_ttadapter != null)
{
_ttadapter.Wrapped = wrapAdapter;
}
base.Adapter = value;
}
}*/
}
上面的代码工作得很好。问题是当我尝试覆盖 Adapter 属性(现在已被注释掉)时,尝试创建TTListView
对象时出现以下异常:
"Unable to activate instance of type TimeTellApp.TTListView from native handle 40557188. No constructor found for TTListView::.ctor(System.IntPtr, Android.Runtime.JniHandleOwner)"
通常这与 GC 销毁托管映射对象有关,所以到目前为止,我通过保留对对象的引用来解决这类问题。的问题TTListView
是调用构造函数进行初始化时已经出现异常。
我像这样创建一个 TTListView 对象:
TTListView setting_listview = new TTListView(this);
(这是一个Activity
)这里可能是什么问题以及解决它的最佳方法是什么?