Search code examples
listviewxamarinxamarin.formstabbedpage

How to refresh a Listview without PullToRefresh in Xamarin.forms


Currently working on a school project where i have a TabbedPage app (Xamarin.form), i have three tabs one for home , second for a listview (it gets data from a database) and a third one for the user profile.

I enabled the PullToRefresh option for the Listview, it works, but in my case data is updated every 2 - 3 minutes , so i have to implement an auto refresh thing. I thinked about updating the listview source on the appearing of the page (OnAppearing) but it does not work.

any Suggestions ? thanks :)


Solution

  • A really simple way, you could start a thread within your Page to perform data refreshing.

    Something like this will get you started

    var myRefreshThread = new Thread (new ThreadStart (async delegate {
       while (true) {
           // Perform your data fetch 
    
           InvokeOnMainThread ( () => {
              // Update the UI on the UIthread
           });
    
           await Task.Delay (180000);
       }
    })).Start ();