locked
Refresh ListView OnResume RRS feed

  • Question

  • User246254 posted

    How do I tricker a ListView refresh OnResume?

    This is a ListView in a ContentPage that also needs to pull fresh data from a SQLite database.

    So when the person resumes the app, this should trigger a function that grabs the data again from the SQLite database and updates the ListView. The last part (grabbing from db and updating) is not a problem but it's at the moment only being triggered by the page loading and a pull to refresh function.

    Friday, September 29, 2017 1:18 PM

Answers

  • User89714 posted

    @KylukeMcDougall - I'd be tempted to use Messaging Center. Have the page that contains the ListView subscribe to messages. Send a message from OnResume. When the subscriber receives it, have it do whatever operations are required to retrieve the latest data, and then update the collection that the ListView is bound to.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, September 29, 2017 1:23 PM

All replies

  • User89714 posted

    @KylukeMcDougall - I'd be tempted to use Messaging Center. Have the page that contains the ListView subscribe to messages. Send a message from OnResume. When the subscriber receives it, have it do whatever operations are required to retrieve the latest data, and then update the collection that the ListView is bound to.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, September 29, 2017 1:23 PM
  • User246254 posted

    @JohnHardman - I had a look into that, however I can't seem to get it to send via the message center to the page that is loaded.

    I tried to pop this into OnResume: MessagingCenter.Send<MainPage>(this, "listRefresh");

    But the problem with that, is that it I get the following error on this in the line above.

    "cannot convert from *.App to *.MainPage". Any ideas what I am perhaps doing wrong?

    App == public class App : Application MainPage == public partial class MainPage : ContentPage

    MainPage is the Navigation Root.

    Friday, September 29, 2017 1:50 PM
  • User246254 posted

    I swapped it around and it seems to be working.

    MessagingCenter.Send<App>(this, "listRefresh");

    Then in the MainPage

    MessagingCenter.Subscribe<App>(this, "listRefresh", (sender) => {});

    Friday, September 29, 2017 2:07 PM