在Paging库中,LiveData pagedList更新后的值不会在第一次活动后观察到

时间:2018-05-04 09:57:44

标签: android-architecture-components android-livedata

我正在使用分页库,在我的viewmodel值的LiveData>中liveData; 正在更新但是活动中的观察者在第一次之后无法观察到变化。和LivePagedListBuilder只返回LiveData,所以我无法用mutableLivedata替换它。

   public class RecipeListViewModel extends AndroidViewModel {
   public LiveData<PagedList<RecipeListPojo>> liveData;
       private Context context;

   public RecipeListViewModel(@NonNull Application application) {
    super(application);
    context=application.getApplicationContext();
}
  public LiveData<PagedList<RecipeListPojo>> init(RecipeDao recipeDao,RecipeFrom recipeFrom,String orderBy) {
  String query=ChefDatabase.getInstance(context).recipeListQueryBuilder(recipeFrom);
    query=query +ORDER_BY+orderBy;
    SimpleSQLiteQuery simpleSQLiteQuery = new SimpleSQLiteQuery(query);
    try {
        liveData = new LivePagedListBuilder(recipeDao.getAllRecipesList(simpleSQLiteQuery), 6).build();


    } catch (Exception e) {
        e.printStackTrace();
    }

    return liveData;

}

0 个答案:

没有答案