SelectionChanged event not getting invoked on Android?

3 posts, 0 answers
  1. Greg
    Greg avatar
    4 posts
    Member since:
    Feb 2017

    Posted 16 May Link to this post

     

    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. Nikolay
    Admin
    Nikolay avatar
    395 posts

    Posted 19 May Link to this post

    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
  3. Greg
    Greg avatar
    4 posts
    Member since:
    Feb 2017

    Posted 22 May in reply to Nikolay Link to this post

    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.

Back to Top