领域查询更改的侦听器

时间:2018-11-03 16:07:19

标签: android realm realm-mobile-platform realm-list realmrecyclerviewadapter

我的活动中有以下代码,我试图从领域中获取数据,然后将其显示在列表中。我使用的监听器效果很好。

private RealmResults<Data> mData = repo.fetchData();
// internally the call is handled by
  realm.where(Data.class).findAllAsync();

mData.addChangeListener(data -> {
    // access to the data stored locally
    // receive updates in case data changes
    // set the data to the list
});

在应用程序的后面,我还希望能够基于用户输入的搜索字符串来过滤上述数据,并在同一侦听器中接收结果。我已经尝试了以下代码。

mData = poiRepo.fetchData("query");

这似乎不起作用,我猜是因为它返回了一个未附加侦听器的新列表。当基础数据未更改或其他任何方式时,有什么方法可以监听领域查询结果中的更改?

我要实现的目标。

mData.addChangeListener(data -> {
    // single place where filtered data is delivered and sent to recycler view
});

function a(){
    repo.fetchData( //filter parameters )
}

function b(){
    repo.fetchData( //filter parameters )
}

function c(){
    repo.fetchData( //filter parameters )
}

0 个答案:

没有答案