parent
32a742f34f
commit
334706904a
@ -1,119 +0,0 @@
|
||||
package edu.hzuapps.diary;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Intent;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
public class cunchuActivity extends AppCompatActivity {
|
||||
|
||||
private Button fanhuibt,qdbt,qcbt;//返回按钮,确定按钮,清除按钮
|
||||
private DatePicker datePicker;//时间计时器
|
||||
private int year,month,day;
|
||||
private DBOpenHelper dbOpenHelper;//声明数据库
|
||||
private EditText editText;//输入框
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_cunchu);
|
||||
|
||||
qcbt = findViewById(R.id.qc);
|
||||
fanhuibt = findViewById(R.id.fanhui3);
|
||||
datePicker = findViewById(R.id.datepicker);
|
||||
qdbt = findViewById(R.id.queding2);
|
||||
editText = findViewById(R.id.edtext);//输入框
|
||||
dbOpenHelper = new DBOpenHelper(cunchuActivity.this,"db_date",null,2);//创建找到数据库
|
||||
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();//创建数据库对象
|
||||
|
||||
//返回上一个页面
|
||||
fanhuibt.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(cunchuActivity.this, jiluActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
//初始化一个日历对象
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
year = calendar.get(Calendar.YEAR);
|
||||
month = calendar.get(Calendar.MONTH);
|
||||
day = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
|
||||
|
||||
///////////////////////时间计时器操作
|
||||
datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() {
|
||||
@Override
|
||||
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
||||
cunchuActivity.this.year = year;
|
||||
cunchuActivity.this.month = monthOfYear;
|
||||
cunchuActivity.this.year = dayOfMonth;
|
||||
|
||||
//****
|
||||
//添加内容在这
|
||||
//****
|
||||
//点确定按钮会做的事情:
|
||||
qdbt.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String str = year+"年"+(monthOfYear+1)+"月"+dayOfMonth+"日";
|
||||
//Toast.makeText(cunchuActivity.this,str,Toast.LENGTH_LONG).show();
|
||||
if (!(editText.getText().toString().equals(""))){
|
||||
insertData(db,year,(monthOfYear+1),dayOfMonth,editText.getText().toString()); //插入数据库
|
||||
Toast.makeText(cunchuActivity.this,"添加成功",Toast.LENGTH_SHORT).show();
|
||||
}else {
|
||||
Toast.makeText(cunchuActivity.this,"请输入事件内容",Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
////////////////////////////////////////////////////////
|
||||
//***
|
||||
//***
|
||||
//删除在这!!
|
||||
//***
|
||||
//***
|
||||
qcbt.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
db.delete("tb_date",null,null);
|
||||
Toast.makeText(cunchuActivity.this,"清除成功",Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//***
|
||||
//***
|
||||
//修改在这!!
|
||||
//***
|
||||
//***
|
||||
private void insertData(SQLiteDatabase sqLiteDatabase , int yearin, int monthin, int dayin, String neirongin){
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("year",yearin);
|
||||
values.put("month",monthin);
|
||||
values.put("day",dayin);
|
||||
values.put("neirong",neirongin);
|
||||
sqLiteDatabase.insert("tb_date",null,values);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue