zoukankan      html  css  js  c++  java
  • 记账本APP6

    对记账本里的记一笔中所填入的数据添加至Sqlite数据库中,之前写体温APP的时候有用到Sqlite数据库,所以在链接数据库这一方面比较方便

    MainActivity.java

    复制代码
     1 public class MainActivity extends AppCompatActivity {
     2 
     3     //记一笔
     4     private ImageButton mAdd;
     5 
     6     @Override
     7     protected void onCreate(Bundle savedInstanceState) {
     8         super.onCreate(savedInstanceState);
     9         setContentView(R.layout.activity_main);
    10 
    11         mAdd=findViewById(R.id.main_btn_add);
    12         mAdd.setOnClickListener(new View.OnClickListener() {
    13             @Override
    14             public void onClick(View v) {
    15                 //跳转到记一笔界面
    16                 Toast.makeText(MainActivity.this,"跳转记一笔界面成功",Toast.LENGTH_SHORT).show();
    17                 Intent intent=null;
    18                 intent=new Intent(MainActivity.this,AddActivity.class);
    19                 startActivity(intent);
    20             }
    21         });
    22     }
    复制代码

    MyDataBaseHelper.java

    复制代码
     1 import android.content.Context;
     2 import android.database.sqlite.SQLiteDatabase;
     3 import android.database.sqlite.SQLiteOpenHelper;
     4 
     5 public class MyDatabaseHelper extends SQLiteOpenHelper {
     6 
     7     private Context mContext;
     8     public MyDatabaseHelper(Context context){
     9         super(context,"AccountBook.db",null,1);
    10         mContext=context;
    11     }
    12 
    13     @Override
    14     public void onCreate(SQLiteDatabase database){
    15         //创建时的回调
    16         String sql="create table " + "AcountBook" + "(type varchar,name varchar,money varchar,time varchar,note varchar)";
    17         database.execSQL(sql);
    18     }
    19 
    20     @Override
    21     public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion){
    22         //升级时的回调
    23     }
    24 
    25 }
    复制代码

    Dao.java

    复制代码
     1 import android.content.Context;
     2 import android.database.sqlite.SQLiteDatabase;
     3 
     4 public class Dao {
     5 
     6     private final MyDatabaseHelper mHelper;
     7 
     8     public Dao(Context context){
     9         //创建数据库
    10         mHelper=new MyDatabaseHelper(context);
    11     }
    12 
    13 }
    复制代码

    Account.java

    复制代码
     1 public class Account {
     2     private String money;
     3     private String time;
     4     private String name;
     5     private String type;
     6     private String note;
     7 
     8     public String getNote() {
     9         return note;
    10     }
    11 
    12     public void setNote(String note) {
    13         this.note = note;
    14     }
    15 
    16     public String getType() {
    17         return type;
    18     }
    19 
    20     public void setType(String type) {
    21         this.type = type;
    22     }
    23 
    24     public String getTime() {
    25         return time;
    26     }
    27 
    28     public void setTime(String time) {
    29         this.time = time;
    30     }
    31 
    32     public String getMoney() {
    33         return money;
    34     }
    35 
    36     public void setMoney(String money) {
    37         this.money = money;
    38     }
    39 
    40     public String getName() {
    41         return name;
    42     }
    43 
    44     public void setName(String name) {
    45         this.name = name;
    46     }
    47 
    48     public Account(String type,String name,String note,String time,String money){
    49         this.money=money;
    50         this.name=name;
    51         this.note=note;
    52         this.time=time;
    53         this.type=type;
    54     }
    55 
    56 }
    复制代码
  • 相关阅读:
    Jsp 中文乱码,解决
    dojox.grid.EnhancedGrid 和 dojox.grid.DataGrid 的继承关系
    使用 Maven 部署 artifact 到 Nexus 教程
    [LeetCode] 187. Repeated DNA Sequences 解题思路
    [LeetCode] 204. Count Primes 解题思路
    [LeetCode] 219. Contains Duplicate II 解题思路
    [LeetCode] 310. Minimum Height Trees 解题思路
    [LeetCode] 200. Number of Islands 解题思路
    PHP7添加mysqli扩展
    MySQL中的锁(表锁、行锁)
  • 原文地址:https://www.cnblogs.com/hanmy/p/14875799.html
Copyright © 2011-2022 走看看