Forum Xamarin.Forms

TableView.ReloadData equivalent for listView?

Rob909Rob909 USMember
edited June 2014 in Xamarin.Forms

I have a listView where the cells have a field that is constantly updated on the backend. I have a timer set up to pull the new data at a set interval, but I don't see anywhere to have the listView refresh itself. For an iOS project I would simply call tableView.ReloadData(). I've tried reassigning the listView.ItemSource property on the main thread, but that didn't work.

I've also tried looking into bindings/observable collections, but those only seem to work for adding/removing items from the list. The number of items in my list aren't going to change, just a property on each item.

Here's a simplified version of the code I'm attempting:

public class Foo {
         List<MyItem> itemList;
         ListView listView;

         public Foo () {
                itemList = new List<MyItem>();

                listView = new ListView();
                listView.ItemTemplate = new DataTemplate (typeof(MyCell));
                listView.ItemsSource = itemList;

                var timer = new Timer (2000);
                timer.Elapsed += OnTimerElapsed;
                timer.Start ();

       public void OnTimerElapsed(object o, ElapsedEventArgs e) {
             Device.BeginInvokeOnMainThread (() => {
                   itemList = beaconLocater.GetAvailableBeacons();
                   listView.ItemsSource = itemList;

Best Answer


  • Rob909Rob909 USMember

    Setting the ItemsSource to null first worked, thanks!

  • idBankMobiledevidBankMobiledev USMember

    Indeed, now, my ListView is in an Auto sized row of a grid.
    how could I get the row resize properly to avoid clipping the newly taller ListView?
    this is on ios in case the solution/workaround is platform specific

  • BartPollitoBartPollito USMember

    Thanks @Daniel Luberda. it worked for me

  • ReinhardSualReinhardSual USMember

    This SAVE me.....
    It works!

  • MarkZhukovskyMarkZhukovsky USMember ✭✭

    the setting to null and resetting of the ItemsSource works but it's ugly (I have images in my ItemTemplate and they flicker when resetting) - surely there has to be a better way to update a single, targeted item? My situation is I have to update an image of a previously tapped item (not currently tapped) which I can identify and "update" but have found no good way to refresh. Thought I found the solution with a hack but alas it only works when the item that needs to be updated is in the current section of the scrollable view....sigh...

  • Resetting the itemSource worked for me thanks although I have a slightly different set up as I am using ReactiveList from ReactiveUI.

Sign In or Register to comment.