【问题标题】:How to update data on fragment resume如何更新片段简历上的数据
【发布时间】:2015-10-24 13:53:53
【问题描述】:

当我的 android 片段加载到堆栈顶部或应用程序恢复或某些按钮单击事件时,我想更新它的数据。我尝试使用附加和分离方法,但它不起作用。我也试过onbackstackchangedlistener(),但没有成功。任何帮助将不胜感激。

【问题讨论】:

  • 显示你到目前为止所做的事情。

标签: android fragment detach


【解决方案1】:

如果你能够让 onResume 像 Shylendra 一样工作,这里的答案就是如何处理它。

把这段代码放进去

onResume()

这是一个示例,说明当您返回片段时想要更新列表视图。

@Override
public void onResume() {
    super.onResume();
    if (allowRefresh)
    {
        allowRefresh = false;
        myListView = db.load_apps();
        getFragmentManager().beginTransaction().detach(this).attach(this).commit();
    }
}

【讨论】:

    【解决方案2】:

    正如他回答here

    片段onResume()onPause() 只会在活动onResume()onPause() 被调用时被调用。 它们与Activity 紧密耦合。

    阅读Handling the Fragment Lifecycle section of this article

    【讨论】:

      猜你喜欢
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多