This is a migrated thread and some comments may be shown as answers.

Detecting Long press on List View

4 Answers 593 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Vaibhav
Top achievements
Rank 1
Vaibhav asked on 02 Feb 2017, 04:31 PM

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.

4 Answers, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 02 Feb 2017, 09:27 PM
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
0
Sheng Kuo
Top achievements
Rank 1
answered on 23 May 2017, 08:37 AM

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!

0
Lance | Manager Technical Support
Telerik team
answered on 23 May 2017, 04:30 PM
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
0
Sheng Kuo
Top achievements
Rank 1
answered on 23 May 2017, 04:54 PM

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!

Tags
ListView
Asked by
Vaibhav
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Sheng Kuo
Top achievements
Rank 1
Share this question
or