是否可以扩展模板化的自定义/子类视图?
也就是说,以下内容是否可以被夸大:
public class TextViewT<T> : TextView
{
List<T> _list;
public TextViewT(Context context) : base(context) { }
public TextViewT(Context context, IAttributeSet attributes) : base(context, attributes) { }
}
如果是这样,这种类型的布局文件中的语法是什么?
具体来说,绝对类名将如何app.droid.views.custom.TextViewT
出现?
<?xml version="1.0" encoding="utf-8"?>
<app.views.custom.TextViewT
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text_view_t"
android:layout_width="match_parent"
android:layout_height="match_parent">
尝试这样做时出现以下异常:
UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'App.Droid.Views.Custom.TextViewT, App.Droid, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
at System.Type.GetType (string,bool) <0x00027>
at Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) <0x00057>
at (wrapper native-to-managed) Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) <0x0006f>
at (wrapper delegate-invoke) <Module>.invoke_void__this___intptr_intptr_intptr_intptr_JValue[] (intptr,intptr,intptr,intptr,Android.Runtime.JValue[]) <0x000cb>
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) <0x00067>
at Android.App.Activity.SetContentView (int) <0x001d7>
at App.Droid.Views.CalendarView.Render () <0x00073>
at MonoCross.Droid.MXActivityView`1<App.ViewModels.CalendarVM>.OnCreate (Android.OS.Bundle) <0x00243>
at App.Droid.Views.CalendarView.OnCreate (Android.OS.Bundle) <0x0001b>
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <0x00057>
at (wrapper dynamic-method) object.cb51fcb8-c099-4fce-b266-642090f4d778 (intptr,intptr,intptr) <0x00043>
谢谢你。