首页 > 代码库 > Other
Other
package org.samsung.miniproject;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by srct on 2017/8/10.
*/
public class OtherActivity extends Activity {
SQLiteDatabase db;
String title_u, remarks_u;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_event_1);
final Intent intent_1 = getIntent();
final String titleArr = intent_1.getStringExtra("T_title");
final String remarksArr = intent_1.getStringExtra("T_remarks");
final String startTimeArr = intent_1.getStringExtra("time");
final String endTimeArr = intent_1.getStringExtra("time_en");
Log.d("","dfeegtfrgef________"+titleArr+" "+remarksArr+" "+startTimeArr+" "+endTimeArr);
// Date date = new Date(startTimeArr);
// String strs = "";
// try {
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// strs = sdf.format(date);
// } catch (Exception e) {
// e.printStackTrace();
// }
// Date date_end = new Date(endTimeArr);
// String str_end = "";
// try {
// SimpleDateFormat simpleDF = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
// str_end = simpleDF.format(date_end);
// } catch (Exception e) {
// e.printStackTrace();
// }
// Log.d("kljio", "d2:" + strs + " " + str_end);
TextView startDate = (TextView) findViewById(R.id.startTime);
TextView endDate = (TextView) findViewById(R.id.endTime);
startDate.setText("开始 " + startTimeArr);
endDate.setText("结束 " + endTimeArr);
EditText editText_title = (EditText) findViewById(R.id.edittitle);
editText_title.clearFocus();
editText_title.setText(titleArr);
EditText editText_remarks = (EditText) findViewById(R.id.remarks);
editText_remarks.clearFocus();
editText_remarks.setText(remarksArr);
db = SQLiteDatabase.openOrCreateDatabase(this.getFilesDir().toString() + "/my_mini_pj.db", null);
//事件删除
Button button_delete = (Button) findViewById(R.id.button_delete);
button_delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
delete(db, titleArr);
Log.d("gdg", "title:" + titleArr);
Intent intent = new Intent();
intent.setClass(OtherActivity.this, MainActivity.class);
OtherActivity.this.startActivity(intent);
finish();
}
});
//事件更新
Button button_update = (Button) findViewById(R.id.button_update);
button_update.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
title_u = ((EditText) findViewById(R.id.edittitle)).getText().toString();
remarks_u = ((EditText) findViewById(R.id.remarks)).getText().toString();
update(db, titleArr, remarksArr);
Intent intent = new Intent();
intent.setClass(OtherActivity.this, MainActivity.class);
OtherActivity.this.startActivity(intent);
finish();
}
});
}
private void update(SQLiteDatabase db, String title, String remarksArr) {
ContentValues values = new ContentValues();
// values.put(“name”, “传智播客”);//key为字段名,value为值
values.put("title", title_u);
values.put("remarks", remarks_u);
db.update("calendar", values, "title=? or remarks=?", new String[]{title, remarksArr});
db.close();
}
private void delete(SQLiteDatabase db, String titles) {
db.delete("calendar", "title=?", new String[]{titles});
db.close();
}
}
Other
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。