我有一个包含一些用户选择的项目的列表。我的 CustumCellViewTemplate 有一个“取消选择”控件,可以从列表中删除单元格。 当列表完全充满项目时,“取消选择”控件起作用,但是当我想删除最后一个项目或者最后一个项目出现在 ListView 中时,我得到了这个异常:
"System.NullReferenceException: Object reference not set to an instance of an object.
at Xamarin.Forms.Platform.Android.ListViewAdapter.IsEnabled (System.Int32 position) [0x0002a] in D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ListViewAdapter.cs:413
at Android.Widget.BaseAdapter.n_IsEnabled_I (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 position) [0x00008] in <263adecfa58f4c449f1ff56156d886fd>:0
at (wrapper dynamic-method) System.Object.389216aa-a260-49e0-aaaa-e4e2031ad22f(intptr,intptr,int)"
这是我的配置:
Mono 8.1
Xamarin.Forms 3.3.0.893527-pre3
Xamarin.Android.Support.Design 27.0.2.1
Xamarin.Android.Support.v7.AppCompat 27.0.2.1
Xamarin.Android.Support.v4 27.0.2.1
Xamarin.Android.Support.v7.CardView 27.0.2.1
Xamarin.Android.Support.v7.MediaRouter 27.0.2.1
Xamarin.GooglePlayServices.Location 60.1142.1
Xamarin.GooglePlayServices.Maps 60.1142.1
Xamarin.Essentials 0.10.0-preview
请问您知道如何解决这个问题吗?
问候
最佳答案
您现在可能已经解决了您的问题,但请将其留在这里供其他遇到此问题的人使用。
感谢 Jason 的问题,它引导我清理了对 ListView 逻辑的可绑定(bind)项源的操作。我做了很多我不需要做的 .Clear() 和 Add 操作。我减少了这些数量,它解决了我的问题。所以我会看看你是如何搞乱 ListView 的 ItemSource 的。
关于xamarin - 如何解决 Xamarin.Forms.Platform.Android.ListViewAdapter.IsEnabled 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52783736/