Dao 层
package bw.com.bawei.bawei.yuemo2.dao;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import java.util.ArrayList;
import java.util.List;
import bw.com.bawei.bawei.yuemo2.bean.Bean;
import bw.com.bawei.bawei.yuemo2.sql.Sql;
public class Dao {
private final SQLiteDatabase database;
public Dao(Context context){
Sql sql = new Sql(context);
database = sql.getWritableDatabase();
}
//添加啊
public long addAll(Bean.ResultBean bean){
ContentValues values = new ContentValues();
values.put("name",bean.getName());
values.put("imageUrl",bean.getImageUrl());
long insert = database.insert("users", null, values);
return insert;
}
public List<Bean.ResultBean> query(){
Cursor cursor = database.query("users", null, null, null, null, null, null, null);
List<Bean.ResultBean> list = new ArrayList<>();
while (cursor.moveToNext()){
String name = cursor.getString(cursor.getColumnIndex("name"));
String imageUrl = cursor.getString(cursor.getColumnIndex("imageUrl"));
list.add(new Bean.ResultBean(name,imageUrl));
}
return list;
}
}
sql
//进行网络判断