UserDaouserDao = DaoMaster.newDevSession(getBaseContext(), UserDao.TABLENAME).getUserDao();
//创建空集合
private ArrayList list = new ArrayList();
//在showData
//便利循環
for (int i = 0;
i < data.size();
i++) {
//添加進空集合
Bean.DataBean dataBean = data.get(i);
list.add(new User(dataBean.getUrl(), dataBean.getTitle()));
}
//添加數據庫
for (int i = 0;
i < list.size();
i++) {
User user = list.get(i);
userDao.insertOrReplace(user);
}
Log.i("aaa", "接收网络数据: " + mCanString);
//panduan
boolean networkConnected = NetWork.isNetworkConnected(MainActivity.this);
if (networkConnected) {
ePresenter.request();
} else {
Toast.makeText(this, "沒有網絡", Toast.LENGTH_SHORT).show();
//查询数据库
List all = userDao.loadAll();
//给rv设置布局管理器
LinearLayoutManager layoutManager1 = new LinearLayoutManager(MainActivity.this, LinearLayoutManager.VERTICAL, false);
Rlv.setLayoutManager(layoutManager1);
BAdapter bAdapter = new BAdapter(R.layout.item_fresco, all);
Rlv.setAdapter(bAdapter);
【数据库储存】//工具类
public static boolean isNetworkConnected(Context context) {
//获取网络连接状态管理器
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//得到网络信息
NetworkInfo info = cm.getActiveNetworkInfo();
if (info != null) {return info.isAvailable();
}return false;
}