安卓记账本开发——数据库创建和数据测试
项目已同步到 GitHub https://github.com/YourDeepEnd/HouseHoldBook
目前界面
部分源码
DatabaseHelper.java
package com.example.householdbook; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import androidx.annotation.Nullable; public class DatabaseHelper extends SQLiteOpenHelper { public DatabaseHelper(Context context) { super(context, "imooc_daily", null, 1); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("create table if not exists imooc_cost("+ "id integer primary key, "+ "cost_title varchar, "+ "cost_date varchar, "+ "cost_money varchar)" ); } public void insertCost(CostBean c){ SQLiteDatabase database = getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put("cost_title",c.costTitle); cv.put("cost_date",c.costDate); cv.put("cost_money",c.costMoney); database.insert("imooc_cost",null,cv); } public Cursor getAllCostData(){ SQLiteDatabase database = getWritableDatabase(); return database.query("imooc_cost",null,null,null,null,null,"cost_date "+"ASC"); } public void deleteAllCostData(){ SQLiteDatabase database = getWritableDatabase(); database.delete("imooc_cost",null,null); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } }
相关推荐
yanyongtao 2020-11-02
dangai00 2020-07-18
MrFuWen 2020-06-28
boredbird 2020-06-26
fengling 2020-06-16
MIKUScallion 2020-06-11
80447704 2020-06-09
XuDanT 2020-06-07
MrFuWen 2020-06-06
aNian 2020-06-03
dongxurr 2020-06-01
冒烟儿 2020-06-01
Roka 2020-05-25
zhangdy0 2020-05-25
ErixHao 2020-05-20
ErixHao 2020-05-16