package com.example.biji;import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class NoteDatabase extends SQLiteOpenHelper {
public static final String TABLE_NAME = "notes";
public static final String CONTENT = "content";
public static final String ID = "_id";
public static final String TIME = "time";
public static final String MODE = "mode";
public static final String PATH = "path";
public static final String FLAG = "flag";
public NoteDatabase(Context context){
super(context, TABLE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME
+ "("
+ ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ CONTENT + " TEXT NOT NULL,"
+ TIME + " TEXT NOT NULL,"
+ PATH + " TEXT NOT NULL,"
+ MODE + " INTEGER DEFAULT 1,"
+ FLAG + " INTEGER NOT NULL);"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
其实这里flag应该设置为布尔值的,但是搞成数值也不大错,,,没有默认值。
来看看具体实现的代码:
@Overridepublic void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (parent.getId()) { /*第几个记录被点击,对应id,然后对应该记录*/
case R.id.lv:
Note curNote = (Note) parent.getItemAtPosition((position));
if(curNote.getFlag()==0){
Intent intent = new Intent(MainActivity.this, EditActivity.class);
intent.putExtra("content", curNote.getContent());
intent.putExtra("id", curNote.getId());
intent.putExtra("time", curNote.getTime());
intent.putExtra("mode", 3); /*代表已经点击过了,与EditActivity接受对应*/
intent.putExtra("tag", curNote.getTag());
intent.putExtra("path", curNote.getPath());
intent.putExtra("flag", 0);
startActivityForResult(intent, 1); /*开始跳转*/
}
else if(curNote.getFlag() == 1) {
final EditText et = new EditText(this);
new AlertDialog.Builder(MainActivity.this)
.setMessage("这是个私密记录哦,你要查看吗,赶紧输入我们的暗号")
.setIcon(android.R.drawable.sym_def_app_icon)
.setView(et)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(et.getText().toString().equals(code)){
Intent intent = new Intent(MainActivity.this, EditActivity.class);
intent.putExtra("content", curNote.getContent());
intent.putExtra("id", curNote.getId());
intent.putExtra("time", curNote.getTime());
intent.putExtra("mode", 3); //代表已经点击过了,与EditActivity接受对应*/
intent.putExtra("tag", curNote.getTag());
intent.putExtra("path", curNote.getPath());
intent.putExtra("flag",1);
startActivityForResult(intent, 1); //开始跳转
}
else{
new AlertDialog.Builder(MainActivity.this)
.setMessage("你的暗号不对呦。");
}
}
}).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {dialog.dismiss();}
}).create().show();
}
break;
}
}