通过片段更新列表视图 [英] Updating listview through fragments

查看:167
本文介绍了通过片段更新列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题,我有一个包含两个片段的活动。片段A有一个ListView和片段B负责更新数据库的,现在我不知道如何从片段中B.更新数据库中的数据,你能不能帮我后立即更新片段A列表视图里面的DATAS并给予样品code这个?非常感谢。

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.

推荐答案

在这个例子中,碎裂调用notify。

In this example, FragmentA call notify.

INotifier

public interface INotifier {
    public void notify(Object data);
}

utils的

public class Utils {
    public static INotifier notifier;
}

碎裂

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
   }
}

这篇关于通过片段更新列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆