本文整理汇总了Java中org.litepal.crud.callback.SaveCallback类的典型用法代码示例。如果您正苦于以下问题:Java SaveCallback类的具体用法?Java SaveCallback怎么用?Java SaveCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SaveCallback类属于org.litepal.crud.callback包,在下文中一共展示了SaveCallback类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getListener
import org.litepal.crud.callback.SaveCallback; //导入依赖的package包/类
public SaveCallback getListener() {
return cb;
}
示例2: copyCitysToDB
import org.litepal.crud.callback.SaveCallback; //导入依赖的package包/类
public void copyCitysToDB() {//将所有城市保存到数据库
boolean cityInited = PreferencesUtil.get(CITY_INITED, false);
if (!cityInited) {
File file = new File(DB_PATH, DB_NAME);
if (file.exists()) {//未初始化却存在
file.delete();
}
String allcities = FileUtil.assertFile2String("ChinaCityList.json", MyApplication.getContext());
List<County> countyList = JSONHandleUtil.handleCitiesJSONData(allcities);
//对数据进行排序后存入数据库
Collections.sort(countyList, new CountyComparator());
List<CityDao> cityDaoList = new ArrayList<>();
for (County county : countyList) {
CityDao cityDao = new CityDao();
cityDao.setCityName(county.countyName);
cityDao.setCityId(county.countyNo);
cityDao.setPinyin(county.countyPY);
cityDaoList.add(cityDao);
}
DataSupport.saveAllAsync(cityDaoList).listen(new SaveCallback() {
@Override
public void onFinish(boolean success) {
if (success) {
LogUtil.d("SaveCityDao", "onFinish: " + "Success");
PreferencesUtil.put(CITY_INITED, true);
} else {
LogUtil.d("SaveCityDao", "Failed");
Toast.makeText(MyApplication.getContext(), "城市数据初始化失败,跳转至默认城市,\n重启可重新初始化", Toast.LENGTH_LONG).show();
WeatherActivity.actionStart(MyApplication.getContext(), "CN101280101");
}
}
});
}
}
示例3: listen
import org.litepal.crud.callback.SaveCallback; //导入依赖的package包/类
/**
* Register a callback listener and async task will start executing right away.
* @param callback
* Callback for save records in background.
*/
public void listen(SaveCallback callback) {
cb = callback;
execute();
}