ListView LongPress Exception RRS feed

  • Question

  • User75163 posted

    Using android galaxy s3. I have a listview for which the datatemplate is a textcell. If I have no contextmenu items defined, and press on multiple list items, it throws an exception and the app crashes. So I have no context items defined, I longpress the first list item, then long press the second, it crashes. Exception below:

        03-12 11:56:56.201 E/mono-rt (18044): [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
        03-12 11:56:56.201 E/mono-rt (18044):   at Xamarin.Forms.Platform.Android.CellAdapter.set_ContextView (Android.Views.View value) [0x00000] in <filename unknown>:0 
        03-12 11:56:56.201 E/mono-rt (18044):   at Xamarin.Forms.Platform.Android.CellAdapter.HandleContextMode (Android.Views.View view, Int32 position) [0x00000] in <filename unknown>:0 
        03-12 11:56:56.201 E/mono-rt (18044):   at Xamarin.Forms.Platform.Android.CellAdapter.OnItemLongClick (Android.Widget.AdapterView parent, Android.Views.View view, Int32 position, Int64 id) [0x00000] in <filename unknown>:0 
        03-12 11:56:56.201 E/mono-rt (18044):   at Android.Widget.AdapterView+IOnItemLongClickListenerInvoker.n_OnItemLongClick_Landroid_widget_AdapterView_Landroid_view_View_IJ (IntPtr jnienv, IntPtr native__this, IntPtr native_parent, IntPtr native_view, Int32 position, Int64 id) [0x00019] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/9e05e39f/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Widget.AdapterView.cs:337 
        03-12 11:56:56.201 E/mono-rt (18044):   at (wrapper dynamic-method) object:d230536c-bfc0-4502-a64d-7e68792208ce (intptr,intptr,intptr,intptr,int,long)
    Thursday, March 12, 2015 3:57 PM

All replies

  • User69837 posted

    You should report this as a bug at http://bugzilla.xamarin.com

    Thursday, March 12, 2015 5:29 PM
  • User35693 posted

    Got same error on galasy s3 mini

    Thursday, March 12, 2015 9:33 PM
  • User75196 posted

    Same here

    Thursday, March 12, 2015 11:27 PM
  • User91015 posted

    Nexus 4 (not that I believe that makes a difference) KitKat (might) Xamarin.Android Version: 4.20.0 (Indie Edition) Android SDK: C:\Users\Barton\AppData\Local\Android\android-sdk Supported Android versions: 2.1 (API level 7) 2.2 (API level 8) 2.3 (API level 10) 3.1 (API level 12) 4.0.3 (API level 15) 4.1 (API level 16) => 4.4 (API level 19) <= 5.0 (API level 21) Java SDK: C:\Program Files (x86)\Java\jdk1.7.071 java version "1.7.071" Java(TM) SE Runtime Environment (build 1.7.0_71-b14) Java HotSpot(TM) Client VM (build 24.71-b01, mixed mode, sharing)

    Build Information Release ID: 507020007 Git revision: dcf3f486177d3e625349b51a8f3be807e3fa7712 Build date: 2015-02-24 05:29:53-05 Xamarin addins: ea7c65bb7876e4a876ab365208e94acdf8f330ef

    Friday, March 13, 2015 12:28 AM
  • User91015 posted


    Friday, March 13, 2015 12:31 AM
  • User75163 posted

    @PeterAxelson yep thanks I did create the bug...

    Friday, March 13, 2015 1:54 PM
  • User16414 posted

    Any known workarounds for this?

    Sunday, March 29, 2015 10:52 AM
  • User105293 posted

    Any workarounds found ??

    Wednesday, April 15, 2015 11:06 AM
  • User76049 posted

    According to Jason it should be fixed in 1.4.3-pre1.

    I don't know of a workaround apart from rolling back to 1.3ish (can't remember the specific version as I can't find the thread again). Thankfully our app isn't in production yet.

    Wednesday, April 15, 2015 1:17 PM
  • User98240 posted

    We worked around the issue by creating an a custom renderer for list views and disabling long tap.

    Enclosed is our custom renderer, you probably have to change the namespace and class names. The important change is the Control.LongClickable = false; code.

    using System;
    using Xamarin.Forms;
    using Xamarin.Forms.Platform.Android;
    using RebuyApp.Common.Views;
    [assembly: ExportRendererAttribute(typeof(ExtendedListView), typeof(RebuyApp.Android.Renderers.ExtendedListViewRenderer))]
    namespace RebuyApp.Android.Renderers
        public class ExtendedListViewRenderer : ListViewRenderer
            protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
                if (Control != null) {
                    Control.LongClickable = false;
    Wednesday, April 15, 2015 1:37 PM
  • User105293 posted

    Thank you @OtaMares!

    Thursday, April 16, 2015 7:09 AM
  • User76049 posted


    Nice. thanks for posting.

    Thursday, April 16, 2015 9:06 AM
  • User35492 posted


    Thanks! Worked for me...

    Wednesday, November 11, 2015 9:16 PM
  • User20038 posted

    I'm seeing this after an item has been long pressed into a ContextAction mode and then the list is scrolled. List only has 10 items. Can't trap the exact event that triggers the set_ContextView null reference. Only happens if cachingStrategy is RecycleElement , not RetainElement

    Android 6.0.1 Xamarin.Forms

    Wednesday, January 4, 2017 12:33 AM