-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResearch.java
134 lines (113 loc) · 5.43 KB
/
Research.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package com.example.note;
import android.content.ContentValues;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.content.SharedPreferences;
import androidx.appcompat.app.AppCompatActivity;
public class Research extends AppCompatActivity implements OnClickListener{
Button ButtonDelete,ButtonSave,ButtonCancel;
EditText EditTextContent,EditTextTitle,EditTextREAuthor;
String tranTitle;
String Author;
ImageView showImage;
MyDataBaseHelper dbHelper = new MyDataBaseHelper(this,"Note.db",null,1);
private void InitNote() {
MyDataBaseHelper dbHelper = new MyDataBaseHelper(this,"Note.db",null,1);
SQLiteDatabase db = dbHelper.getWritableDatabase(); //同上,获得可写文件
Cursor cursor = db.query("Note",new String[]{"id","title","author","content","picture"},"title=?",new String[]{tranTitle+""},null,null,null,null);
if(cursor.moveToNext()) { //逐行查找,得到匹配信息
do {
String Title = cursor.getString(cursor.getColumnIndex("title"));
String Author = cursor.getString(cursor.getColumnIndex("author"));
String content = cursor.getString(cursor.getColumnIndex("content"));
String picture = cursor.getString(cursor.getColumnIndex("picture"));
Uri u = Uri.parse(picture);
EditTextREAuthor.setText(Author);
EditTextContent.setText(content);
EditTextTitle.setText(Title);
showImage.setImageURI(u);
} while (cursor.moveToNext());
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_research);
EditTextContent = (EditText)findViewById(R.id.EditTextREEditContent);
EditTextTitle = (EditText)findViewById(R.id.EditTextREEditTitle) ;
ButtonCancel = (Button)findViewById(R.id.ButtonRECancel);
ButtonSave = (Button)findViewById(R.id.ButtonRESave);
ButtonDelete = (Button)findViewById(R.id.ButtonREDelete);
EditTextREAuthor = findViewById(R.id.EditTextREAuthor);
showImage = findViewById(R.id.showImage);
ButtonCancel.setOnClickListener(this);
ButtonSave.setOnClickListener(this);
ButtonDelete.setOnClickListener(this);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
tranTitle = extras.getString("tranTitletoRE"); //接受主界面传来的title值
InitNote();
}
@Override
public void onClick(View v){
switch (v.getId()){
case R.id.ButtonREDelete: //删除该title的日志
Log.d("title is ",tranTitle);
SQLiteDatabase db = dbHelper.getWritableDatabase();
db.delete("Note","title=?",new String[]{tranTitle+""}); //进行字符串匹配
Research.this.setResult(RESULT_OK,getIntent());
Research.this.finish();
break;
case R.id.ButtonRESave: //将文界面内容保存
SQLiteDatabase db1 = dbHelper.getWritableDatabase(); //获取可写文件
Date date = new Date();
ContentValues values = new ContentValues(); //获取信息
String Title = String.valueOf(EditTextTitle.getText());
String Content = String.valueOf(EditTextContent.getText());
if(Title.length()==0){
Toast.makeText(this, "请输入一个标题", Toast.LENGTH_LONG).show();
}else {
values.put("title", Title); //填装信息
values.put("content", Content);
db1.update("Note", values, "title=?", new String[]{tranTitle + ""}); //字符串匹配
Research.this.setResult(RESULT_OK, getIntent()); //返回主界面
Research.this.finish();
}
Author = String.valueOf(EditTextREAuthor.getText());
SharedPreferences.Editor editor = getSharedPreferences("data",MODE_PRIVATE).edit();
editor.putString("author",Author);
editor.apply(); //写入作者信息
break;
case R.id.ButtonRECancel:
Research.this.setResult(RESULT_OK,getIntent());
Research.this.finish();
break;
}
}
}