新的分页库的所有示例都使用了Room库,Room为我们创建了一个数据源.在我自己的情况下,我需要创建我的自定义数据源.
这是我的视图模型类中应该返回实时数据的方法.我的liveata总是返回null.
LiveData<PagedList<ApiResult>> getData(){
LivePagedListProvider<Integer,ApiResult> p = new LivePagedListProvider<Integer, ApiResult>() {
@Override
protected DataSource<Integer, ApiResult> createDataSource() {
return new DataClass();
}
};
listLiveData = p.create(0,new PagedList.Config.Builder()
.setPageSize(5) //number of items loaded at once
.setPrefetchDistance(0)// the distance to the end of already loaded list before new data is loaded
.build());
return listLiveData;
}
Run Code Online (Sandbox Code Playgroud)
这是Data类
public class DataClass extends TiledDataSource<ApiResult> {
private List<ApiResult> result = new ArrayList<>();
@Override
public int countItems() {
return result.size();
}
@Override
public List<ApiResult> loadRange(int startPosition, int count) …Run Code Online (Sandbox Code Playgroud) 我尝试初始化我的 LiveData 对象,但它给出了错误:“LiveData 是抽象的,无法实例化”
LiveData listLiveData = new LiveData<>();
如何从在线位置加载矢量绘图,例如http://arsenal.com/image.xml并将其显示为图像
我想在应用程序关闭时删除我的sqlite数据库.我尝试使用全局类并覆盖了onTerminate()方法.
public class AppController extends Application {
private static AppController mInstance;
public Context context(){
return mInstance.getApplicationContext();
}
@Override
public void onTerminate() {
context().deleteDatabase(DbHelper.DATABASE_NAME);
super.onTerminate();
}
}
Run Code Online (Sandbox Code Playgroud)
它不起作用