我的活动中有以下代码,我试图从领域中获取数据,然后将其显示在列表中。我使用了一个完美的监听器。
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 )
}