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

SelectionChanged event not getting invoked on Android?

2 Answers 537 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 16 May 2017, 09:13 PM

 

On Android, I'm having a problem.  I can click and drag to reorder rows but the SelectionChanged event appears to not get invoked.
I have this in my MainActivity.cs as specified on the Getting Started page:

[assembly: ExportRenderer (typeof (Telerik.XamarinForms.DataControls.RadListView), typeof (Telerik.XamarinForms.DataControlsRenderer.Android.ListViewRenderer))]

 

I assign a method  to the SelectionChanged event like this:

_listV.SelectionChanged += ItemSelectionChanged;

Where ItemSelectionChanged is the method I want to call when the event fires.

The method signature is like this:

private void ItemSelectionChanged (object sender, NotifyCollectionChangedEventArgs e)

I only have this problem on Android.  iOS works fine. I'm using Xamarin Forms and Telerik.UI for Xamarin version 2017.1.10321.10
Am I missing something?

2 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 19 May 2017, 08:28 AM
Hello Greg,

Currently there are some inconsistencies between Android and iOS in this scenario.It's in our plans to introduce new API for this behavior that would provide the required consistency between different platforms. 

When it comes to the SelectionChanged event the way it works is that it's fired every time you tap to select a different item, however, it is not invoked if you're dragging an item, as it is still the selected one even after it's dropped and its position changed.

In case you need an event fired after you have dropped the item and changed its position you would need to use an ObservableCollection as source and subscribe to CollectionChanged : 

public class ViewModel
{
public ViewModel ()
{
            this.Source = new ObservableCollection<SourceItem> { new SourceItem("1"), new SourceItem("2"), new SourceItem("3") };

            this.Source.CollectionChanged += Source_CollectionChanged;
}

        private void Source_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            Console.WriteLine("Item moved event fired");
        }

        public ObservableCollection<SourceItem> Source { get; set; }
}

This way the event will be triggered every time an item's position is changed. 

Regards,
Nikolay
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
Greg
Top achievements
Rank 1
answered on 22 May 2017, 06:37 PM

Hi, Nikolay

Thank you for your reply.

I've tried your suggestion of using an ObservableCollection and subscribing to the CollectionChanged event.

In a simple test app, this works very well, but in our production app on Android, the ObservableCollection appears to not get changed.  We don't have this issue on iOS.

I'm currently trying to reproduce this behavior in the sample app.  If/when I can make that happen, I will send you an updated sample app.

Tags
ListView
Asked by
Greg
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Greg
Top achievements
Rank 1
Share this question
or