android调用本地数据库存储数据sqlite
private View.OnClickListener save2 = new View.OnClickListener() {
@Override
public void onClick(View v) {
// 添加数据进数据库
Textweek=tvWeek.getText().toString().trim();
Textsection=tvSection.getText().toString().trim();
Textteachername=tvTeacherName.getText().toString().trim();
Textclassroom=tvClassRoom.getText().toString().trim();
Textclassname=tvClassName.getText().toString().trim();
Textbegintime=tvBegin.getText().toString().trim();
Textbegintime2=tvBegin2.getText().toString().trim();
Textendtime=tvEnd.getText().toString().trim();
Textendtime2=tvEnd2.getText().toString().trim();
Textexamtime=tvExamTime.getText().toString().trim();
ClassDb key = new ClassDb(AddClass.this);
ClassInfo keyInfo = new ClassInfo();
keyInfo.lockType = 1;
keyInfo.setWeek(Textweek);
keyInfo.setSection("第" Textsection "节");
keyInfo.setTeacherName(Textteachername);
keyInfo.setClassRoom(Textclassroom);
keyInfo.setClassName( Textclassname);
keyInfo.setStartTime(Textbegintime "点" Textbegintime2 "分");
keyInfo.setEndTime(Textendtime "点" Textendtime2 "分");
keyInfo.setExamTime(Textexamtime);
key.addClass(keyInfo);
Toast.makeText(getApplicationContext(), "添加课程成功!", Toast.LENGTH_SHORT).show();
finish();
Intent intent = new Intent();
intent.setClass(AddClass.this, MainActivity.class);
startActivity(intent);
}
};
private View.OnClickListener cancel2 = new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
Intent intent = new Intent();
intent.setClass(AddClass.this, MainActivity.class);
startActivity(intent);
}
};
// 按键事件
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// 手机上面的返回键
// ExitApplication.getInstance().exit();
}
if (keyCode == KeyEvent.KEYCODE_MENU) {
System.exit(0);
}
return super.onKeyDown(keyCode, event);
}
评论