简体   繁体   English

从第三个片段刷新第一个片段的列表

[英]Refresh list of first fragment from third fragment

My question is how to refresh the list on first fragment after work done on the third fragment ?我的问题是如何在完成第三个片段的工作后刷新第一个片段的列表?
Check this flow before any answers come out.在任何答案出来之前检查这个流程。
1. On MyActivity, I have the first fragment named as " ABC ". 1. 在 MyActivity 上,我将第一个片段命名为“ ABC ”。
2. On button click of " ABC ", move to second fragment " JKL " (without removing the first fragment). 2.点击“ ABC ”按钮,移动到第二个片段“ JKL ”(不删除第一个片段)。
3. On button click of " JKL ", move to third fragment " XYZ " and removes second fragment " JKL ". 3. 点击“ JKL ”按钮,移动到第三个片段“ XYZ ”并移除第二个片段“ JKL ”。
4. After work is done on third fragment " XYZ ", third fragment " XYZ " removed and first fragment " ABC " comes front but unable to refresh the list on first fragment " ABC " since it is kept as it is. 4. 在第三个片段“ XYZ ”上工作完成后,第三个片段“ XYZ ”被移除,第一个片段“ ABC ”出现在前面但无法刷新第一个片段“ ABC ”上的列表,因为它保持原样。
5. I know the Interface, but it works as one-to-one . 5. 我知道接口,但它是一对一的
6. even, How do I send a string-value to the first fragment from the third fragment that I will use to refresh the list? 6. 甚至,如何将字符串值从我将用于刷新列表的第三个片段发送到第一个片段?
7. 7.

I cannot remove the first fragment due to preserving its last state as it is由于保留了它的最后状态,我无法删除第一个片段

Since you are not replacing the ABC fragment, you can just ask the Fragment to refresh itself by having a public method in it, that is called by the parent Activity.由于您没有替换 ABC 片段,因此您可以通过在其中包含一个由父 Activity 调用的公共方法来要求 Fragment 刷新自身。

  1. Hold the reference to your ABC fragment in the Activity在 Activity 中保留对 ABC 片段的引用
  2. Have an interface in the XYZ fragment, that is implemented by the parent Activity在 XYZ 片段中有一个接口,即由父 Activity 实现
  3. When something happens in XYZ, call the interface method, which in turn calls the ABC's refresh method当XYZ有事情发生时,调用接口方法,接口方法依次调用ABC的refresh方法

Ideally I would replace the ABC fragment and use the lifecycle callbacks to do the refresh.理想情况下,我会替换 ABC 片段并使用生命周期回调来进行刷新。 But for your case, you can follow the above steps.但是对于您的情况,您可以按照上述步骤操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM