here is my problem I have an activity that contains two fragments. Fragment A have a listview and Fragment B is in charge of updating the database now I don't know how to update the datas in listview inside Fragment A right after updating the data in Database from Fragment B. Can you help me and give a sample code for this? Thanks a lot.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
In this example, FragmentA call notify.
INotifier
public interface INotifier {
public void notify(Object data);
}
Utils
public class Utils {
public static INotifier notifier;
}
FragmentA
public FragmentA extends Fragment {
public void onCreateView(...) {
}
public void inSomeMethod() {
if (Utils.notifier != null) {
Utils.notifier.notify(data);
}
}
}
FragmentB
public FragmentB extends Fragment implements INotifier {
public void onCreateView(...) {
Utils.notifier = this;
}
@Override
public void notify(Object data) {
// handle data
}
}