首页 > 解决方案 > 如何解决 Xamarin.Forms.Platform.Android.ListViewAdapter.IsEnabled 异常?

问题描述

我有一个包含一些用户选定项目的列表。我的 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

请问您知道如何解决这个问题吗?

问候

标签: xamarinexceptionxamarin.formsxamarin.android

解决方案


您现在可能已经解决了您的问题,但只是将其留给遇到此问题的其他人。

感谢 Jason 的问题,它让我清理了我对列表视图逻辑的可绑定 itemsource 的操作。我做了很多 .Clear() 和 Add 我不需要做的事情。我减少了这些的数量,它为我解决了这个问题。所以我会看看你是如何弄乱列表视图的 ItemSource 的。


推荐阅读