Android开发之SQLite(手机记账App)

MainActivity.class 源码片段

private static final String TAG = “SQLiteLOG”;
private MenuSelect menuSelect;
public int _id;
private Button but_save,but_update,but_delete;
private EditText name,money,remark;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

fab.setVisibility(0);

fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, “Replace with your own action”, Snackbar.LENGTH_LONG)
.setAction(“Action”, null).show();
}
});

name = (EditText)findViewById(R.id.item_name);
money = (EditText)findViewById(R.id.item_money);
remark = (EditText)findViewById(R.id.item_remark);

Bundle bundle = getIntent().getExtras();
if(bundle != null){
_id = Integer.valueOf(bundle.getString(“id”));
name.setText(bundle.getString(“name”));
money.setText(bundle.getString(“money”));
remark.setText(bundle.getString(“remark”));

}
init(this);

}

SQLite的使用

1、从官网下载SQLite(http://www.sqlite.org/download.html)安装后(Mac自带SQLite,也可直接运行下面的命令),打开终端更改目录到sqlite3文件所在的目录,输入如下命令便可以创建一个数据库,如果该数据库已存在将打开:

 
Copyright © 2008-2021 lanxinbase.com Rights Reserved. | 粤ICP备14086738号-3 |