Detecting Long press on List View

5 posts, 0 answers
  1. Vaibhav
    Vaibhav avatar
    11 posts
    Member since:
    Nov 2016

    Posted 02 Feb Link to this post

    Hello guys,

    I am looking for the List View having long press functionality. Actually I am showing the data in List View. As soon as I long press any item, each item get check box in front it. So is it possible to do such type of functionality in xamarin forms. Please help.

     

    Thank you.

  2. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    362 posts

    Posted 02 Feb Link to this post

    Hello,

    You'll find all the functionality for RadListView selection here.

    Anything else, you'd need to implement manually. A long press does different things depending on the OS you're on, therefore applying a single type of action from the component would not be recommended. For example, on windows Phone, a long press open a Context Menu, not selection.

    You can find different suggestions and example in the Xamarin Forums, here's just one example.

    Regards,
    Lance | Tech Support Engineer, Sr.
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Sheng Kuo
    Sheng Kuo avatar
    10 posts
    Member since:
    May 2017

    Posted 23 May in reply to Lance | Tech Support Engineer, Sr. Link to this post

    Hello Lance,

    I'm a RadListView user, I found that the EnableItemOrder can do nothing to me, because I can't detect when is the ordering finished, it means I can reorder items by drag and drop, but I can't update anything after user dropped item to reorder items,

    do you have any solution for this issue??

    I felt worrying about it after I successfully bought the UI for Xamarin Forms.

    Please help.

    Thank you!

  4. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    362 posts

    Posted 23 May Link to this post

    Hello Sheng,

    Since you have a license, you can open a support ticket here. This will allow me (or anyone else from the UI for Xamarin engineering team) to work with you a little more closely. A support ticket carries a guaranteed response time as well.

    Pertaining to the question itself, you can either use the SelectionChanged event or use the ListView's bound ObservableCollection.CollectionChanged event to see exactly what is occurring via the NotifyCollectionChangedEventArgs.

    As an example, here's a simple view model with a collection for the ListView ItemsSource. Notice the event handler for CollectionChanged. You can see what exactly happens to an item under each Action condition:

    public class ViewModel
    {
        public ViewModel()
        {
            MyListViewItems.CollectionChanged += MyListViewItemsOnCollectionChanged;
        }
     
        public ObservableCollection<MyItem> MyListViewItems { get; set; }
     
        private void MyListViewItemsOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            switch (args.Action)
            {
                case NotifyCollectionChangedAction.Add:
                    break;
                case NotifyCollectionChangedAction.Move:
                    break;
                case NotifyCollectionChangedAction.Remove:
                    break;
                case NotifyCollectionChangedAction.Replace:
                    break;
                case NotifyCollectionChangedAction.Reset:
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
    }


    Additionally in you can see what items were part of that action via the args other properties:

    case NotifyCollectionChangedAction.Move:
        var x = args.NewItems;
        var y = args.NewStartingIndex;


    Lastly, if you're not using MVVM and want to do this in the code-behind, the RadListView.SelectionChanged event also uses NotifyCollectionChangedEventArgs, so you can use the same approach as above.

    If you have any further trouble, open a support ticket, attach your problematic code and we'll dig deeper.

    Regards,
    Lance | Tech Support Engineer, Sr.
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Sheng Kuo
    Sheng Kuo avatar
    10 posts
    Member since:
    May 2017

    Posted 23 May in reply to Lance | Tech Support Engineer, Sr. Link to this post

    Lance,

    You are time saver! Apologize for my rude comment above, you solved my big problem and save a lot of time with it.

    Thank you!

Back to Top