How to restrict listview for multi item select at a time?

HarshitaHarshita INMember ✭✭✭

I have a listview inside my content page,on listview item select it will open the edit page.But user can select multiple list item with his fingers at a time.
So how to restrict listview so that user can only open single item at a time?
How to solve this?

Answers

  • Gigex42Gigex42 USMember ✭✭✭✭

    So you mean if the user is fast enough he can tap on multiple items which will lead each item to go to the detail page?

    If so just create an IsBusy property.

    When the user taps an item check if the property is true. If yes, dont navigate. If its false then set it to true and after the navigation set it back to false.

  • ColeXColeX Member, Xamarin Team Xamurai
    edited July 2018

    We can disable the multi touch on listview via Custom Renderer .

    iOS

    [assembly: ExportRenderer(typeof(Xamarin.Forms.ListView), typeof(CustomListViewRenderer))]
    namespace Forms.iOS
    {
        class CustomListViewRenderer : ListViewRenderer
        {
    
            protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
            {
                base.OnElementChanged(e);
                if (e.NewElement != null)
                {
                    Control.MultipleTouchEnabled = false;
                }
            }
        }
    }
    

    Android

    [assembly: ExportRenderer(typeof(Xamarin.Forms.ListView), typeof(CustomListViewRenderer))]
    namespace Forms.Droid
    {
        class CustomListViewRenderer : ListViewRenderer
       {
           Context _context;
    
           public CustomListViewRenderer(Context context) : base(context)
           {
               _context = context;
           }
    
           protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ListView> e)
           {
                base.OnElementChanged(e);
                if (e.NewElement != null)
               {
                    Control.MotionEventSplittingEnabled = false;
               }
           }
       }
    }
    

    Refer

    https://stackoverflow.com/questions/23889848/prevent-uitableview-from-receiving-two-touches-nested-pop-animation-can-result/36474514

    https://stackoverflow.com/questions/20517763/avoid-multi-touch-on-list-view-android-4-2-2

  • HarshitaHarshita INMember ✭✭✭

    @ColeX
    Its not working,it also open multiple window when user touch multiple item at a time. :(

  • Xami3Xami3 PKMember, University ✭✭✭

    @Gigex42 said:
    So you mean if the user is fast enough he can tap on multiple items which will lead each item to go to the detail page?

    If so just create an IsBusy property.

    When the user taps an item check if the property is true. If yes, dont navigate. If its false then set it to true and after the navigation set it back to false.

    yes @Gigex42 is right

Sign In or Register to comment.