private boolean hasNewWork(){
ConnectivityManager cm = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
return activeNetworkInfo!=null && activeNetworkInfo.isAvailable();
}
调用
if (!hasNewWork()){
Toast.makeText(this,"无网络,正在从数据库获取数据",Toast.LENGTH_SHORT).show();
List query = greenDaoUtils.query();
myAdapter.setUserList(query);
}
rec.setLoadingListener(new XRecyclerView.LoadingListener() {
@Override
public void onRefresh() {
rec.refreshComplete();
}
@Override
public void onLoadMore() {
Toast.makeText(MainActivity.this,"无更多数据",Toast.LENGTH_SHORT).show();
rec.loadMoreComplete();
}
});