问题是在调用onchanged方法后,recycleler视图不显示数据。或者如果是,则显示信息需要很长时间。继承人代码:
mViewModel.getMutableLiveData().observe(this, new Observer<Filters>() {
@Override
public void onChanged(@Nullable Filters filters) {
if (filters != null){
Log.d("ExploreFragObserver", filters.getCategory() + " ");
Log.d("ExploreFragObserver", filters.getCity() + "");
Log.d("ExploreFragObserver", filters.getSortBy() + " ");
Log.d("ExploreFragObserver", filters.getPrice() + " ");
onFilter(filters);
Log.d("Done Loading Adapt", filters.getSortBy() + " ");
Log.d("ExploreFragObserver", filters.getCategory() + " ");
Log.d("ExploreFragObserver", filters.getCity() + "");
Log.d("ExploreFragObserver", filters.getSortBy() + " ");
Log.d("ExploreFragObserver", filters.getPrice() + " ");
// onFilter(Filters.getDefault());
}
}
});
这是方法被调用的地方,我从viewmodel获取数据,没有问题但回收者视图剂量显示数据。
{
"item": [
{
"item_id": 484,
"user_id": 123,
"lucky_number": -1,
"liked_user": [
{
"user_id": 2
},
{
"user_id": 1
}
],
"modified_time": "0000-09-19 10:24:02"
}
]
}
对话框片段在viewmodel中设置filters对象的数据,该片段和调用片段都共享。
答案 0 :(得分:0)
我认为您忘记添加adapter.startListening()
。