我正在使用分页库,在我的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;
}