1
我有一個具有多個參數化構造函數的類。使用參數化構造函數創建類的對象c#
class MyClass{
public MyClass(Context context) : this(context, VERTICAL)
{
}
public MyClass(Context context, int Orientation) : base(context)
{
init(context, Orientation);
}
public MyClass(Context context, Android.Util.IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
{
//more code
}
// I have to make an object of this MyClass into MyDataSetObserver class.
public class MyDataSetObserver : DataSetObserver
{
MyClass mc;
public MyDataSetObserver(MyClass _mc)
{
mc= _mc;
}
public override void OnChanged()
{
mc.onDataChanged();
}
public override void OnInvalidated()
{
mc.onDataChanged();
}
}
//DatasetObserver usage
public void setAdapter(Android.Widget.IAdapter myadapter, int initialPosition)
{
if (this.adapter != null)
{
this.adapter.UnregisterDataSetObserver (adapterDataObserver);
}
//Assert.assertNotNull ("adapter should not be null", adapter);
this.adapter = myadapter;
adapterDataCount = adapter.Count;
adapterDataObserver = new MyDataSetObserver (this);
this.adapter.RegisterDataSetObserver (adapterDataObserver);
if (adapterDataCount > 0) {
SetSelection (initialPosition);
}
}
}
,但是這給了我MC爲空值..
另外,我需要做一個構造函數鏈,這是正確的做法?
顯示的'MyDataSetObserver' –
的使用碼@Gokul請參閱更新 – user3034944
在哪裏出現了MC一片空白?在MyDataSetObserver構造函數中? – StevieB