【发布时间】:2017-10-10 13:54:29
【问题描述】:
我已尝试在 Android 架构组件中使用 google 提供的 Room 实现分页库。但它在我的 UserDao 类中显示编译时错误
这是错误:
Error:(22, 42) error: Not sure how to convert a Cursor to this method's return type
我的问题是什么返回类型?
UserDao.java
@Dao
public interface UserDao {
@Query("SELECT * FROM user")
LiveData<List<User>> getAll();
//Compile Error is here : Not sure how to convert a Cursor to this method's return type
@Query("SELECT * FROM user")
LivePagedListProvider<Integer, User> userByPagination();
}
这里是 UserModel.java
public class UserModel extends AndroidViewModel {
private final UserDao userDao;
public UserModel(Application application) {
super(application);
userDao = RoomDB.getDefaultInstance().userDao();
}
public LiveData<List<User>> getAllUser() {
return userDao.getAll();
}
public LiveData<PagedList<User>> getAllUserPagination() {
return userDao.userByPagination().create(
/* initial load position */ 0,
new PagedList.Config.Builder()
.setEnablePlaceholders(true)
.setPageSize(10)
.setPrefetchDistance(5)
.build());
}
}
我参考了以下示例:
我已提出问题HERE
任何帮助将不胜感激
【问题讨论】:
标签: java android paging android-room android-architecture-components