【问题标题】:How can i update my data in xamarin without closing and opening my app?如何在不关闭和打开我的应用程序的情况下更新 xamarin 中的数据?
【发布时间】:2021-03-19 11:49:59
【问题描述】:

我有一种方法可以制作网格表并从网站获取 json 数据,但该网站的数据总是在变化。所以我需要关闭我的应用程序并重新打开它以刷新数据。如何在不关闭并重新打开我的应用程序的情况下做到这一点?如何刷新页面以更新数据?

public MainPage()
{
    InitializeComponent();
    GetTable();
}

public void GetTable()
{
    //It have my codes for create table and get datas from json
}

【问题讨论】:

  • 添加一个按钮来按需刷新数据。或者使用计时器定期更新数据。添加下拉刷新控件。有很多不同的方法可以解决这个问题。
  • @Jason 我尝试为它添加按钮。但是我的方法也创建了新行或什么。因此,当我单击它时,它也会创建新的空行,因此会产生一些问题。单击并重新运行时可以删除我的方法吗?有可能做这样的事情吗?
  • 如果您需要帮助调试您的代码,那么您需要发布您的代码并专门寻求帮助解决该特定问题。你实际上问的是一个非常广泛、不具体的问题,不可能给出具体的答案。
  • 正如 Jason 所建议的,您可以使用计时器或添加按钮或下拉刷新控件来触发更新。如果您确实绑定到视图,则 ui 更新将毫无问题地工作。对于列表,您可以使用 observablecollection 这将确保添加和删除数据将反映在视图中。如果有任何字段更新,则使用属性并在有更新时发布引发属性更改事件。

标签: c# xamarin xamarin.forms xamarin.android


【解决方案1】:

试着这样做吧..

public MainPage() {
  InitializeComponent();
  ValidateDatabase();
}




public async Task ValidateDatabase() {
  //It have my codes for create table and get datas from json

  await loadComponentsFromDatabase();
}


private async Task loadComponentsFromDatabase()

{
  // your operation to the database, and render it to the users

  // note that all components must render here and not in InitializeComponent.

  // so all your components must be visible= false until you are here and make 

  // visible = true

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-19
    • 2013-03-13
    • 1970-01-01
    • 2017-06-16
    • 2011-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多