【问题标题】:Inflating a Generic/Templated Custom View膨胀通用/模板化自定义视图
【发布时间】:2013-09-16 15:43:07
【问题描述】:

是否可以扩展模板化的自定义/子类视图?

也就是下面的可以膨胀吗:

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>

谢谢。

【问题讨论】:

标签: c# android xamarin.android xamarin


【解决方案1】:

好吧,既然它在原始 android 中是不可能的,那么它在 Xamarin.Android 中肯定是不可能的:

Adding a custom view to XML... but with a GENERIC-type

【讨论】:

    猜你喜欢
    • 2012-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-18
    • 1970-01-01
    • 2019-01-10
    • 1970-01-01
    相关资源
    最近更新 更多