ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Android 记事本NotePad,flutter安装包优化

2021-12-29 14:01:45  阅读:173  来源: 互联网

标签:note db NotePad NOTE cursor new Android 安装包 COL


// Create table

@Override

public void onCreate(SQLiteDatabase db) {

String createNoteTableSql = “CREATE TABLE " + NOTE_TABLE_NAME + " (”

  • NOTE_COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + NOTE_COL_TITLE

  • " TEXT," + NOTE_COL_CONTENT + " TEXT," + NOTE_COL_CREATED

  • " INTEGER," + NOTE_COL_MODIFIED + " INTEGER" + “);”;

db.execSQL(createNoteTableSql);

}

@Override

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

// Drop older table if existed

db.execSQL("DROP TABLE IF EXISTS " + NOTE_TABLE_NAME);

// Create tables again

onCreate(db);

}

// Add new note

public int addNote(Note note) {

SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();

values.put(NOTE_COL_TITLE, note.getTitle());

values.put(NOTE_COL_CONTENT, note.getContent());

values.put(NOTE_COL_CREATED, note.getCreated());

values.put(NOTE_COL_MODIFIED, note.getModified());

// Insert to database

long rowId = db.insert(NOTE_TABLE_NAME, null, values);

// Close the database

db.close();

return (int) rowId;

}

// Get one note

public Note getNote(int id) {

SQLiteDatabase db = this.getReadableDatabase();

Cursor cursor = db.query(NOTE_TABLE_NAME, NOTE_COL_PROJECTION,

NOTE_COL_ID + “=?”, new String[] { String.valueOf(id) }, null,

null, null, null);

if (cursor != null)

cursor.moveToFirst();

Note note = new Note(cursor.getInt(0), cursor.getString(1),

cursor.getString(2), cursor.getLong(3), cursor.getLong(4));

return note;

}

// Get all notes

public List getAllNotes() {

List noteList = new ArrayList();

String selectQuery = "SELECT * FROM " + NOTE_TABLE_NAME;

SQLiteDatabase db = this.getWritableDatabase();

Cursor cursor = db.rawQuery(selectQuery, null);

// looping through all rows and adding to list

if (cursor.moveToFirst()) {

do {

Note note = new Note(cursor.getInt(0), cursor.getString(1),

cursor.getString(2), cursor.getLong(3),

cursor.getLong(4));

noteList.add(note);

} while (cursor.moveToNext());

}

// return contact list

return noteList;

}

public Cursor getAllNotesCursor() {

String selectQuery = "SELECT * FROM " + NOTE_TABLE_NAME;

SQLiteDatabase db = this.getReadableDatabase();

Cursor cursor = db.rawQuery(selectQuery, null);

return cursor;

}

public int updateNote(Note note) {

SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();

values.put(NOTE_COL_TITLE, note.getTitle());

values.put(NOTE_COL_CONTENT, note.getContent());

values.put(NOTE_COL_CREATED, note.getCreated());

values.put(NOTE_COL_MODIFIED, note.getModified());

return db.update(NOTE_TABLE_NAME, values,

NOTE_COL_ID + “=?”, new String[] { String.valueOf(note.getId()) });

}

public void deleteNote(int noteId) {

SQLiteDatabase db = this.getWritableDatabase();

db.delete(NOTE_TABLE_NAME, NOTE_COL_ID + “=?”,new String[] { String.valueOf(noteId) } );

db.close();

}

public void deleteAllNotes() {

SQLiteDatabase db = this.getWritableDatabase();

db.delete(NOTE_TABLE_NAME, null, null);

db.close();

}

}

新建和修改便签:

package com.zms.notepad;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

/**

  • Created by AlexZhou on 2015/2/3.

  • 11:14

*/

public class NoteNew extends Activity {

private EditText etTitle; //便签标题

private EditText etContent; //便签内容

private Button btnCancel;

private Button btnSave;

private int _noteId; //便签ID

private NoteDbHelper _db;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.note_new);

etTitle = (EditText) findViewById(R.id.etTitle);

etContent = (EditText) findViewById(R.id.etContent);

btnCancel = (Button) findViewById(R.id.btnCancel);

btnSave = (Button) findViewById(R.id.btnSave);

btnCancel.setOnClickListener(new OnClickListenerImp());

btnSave.setOnClickListener(new OnClickL

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

istenerImp());

_db = new NoteDbHelper(this);

Intent intent = getIntent();

_noteId = intent.getIntExtra(NoteList.EXTRA_NOTE_ID, -1);

if (_noteId > 0) {

Note note = _db.getNote(_noteId);

etTitle.setText(note.getTitle());

etContent.setText(note.getContent());

}

}

private class OnClickListenerImp implements View.OnClickListener {

@Override

public void onClick(View v) {

if (v == btnCancel) {

Toast.makeText(NoteNew.this, “天启提示:放弃新建便签”, Toast.LENGTH_SHORT).show();

finish();

} else if (v == btnSave) {

String titleVoid = etTitle.getText().toString();

String contentVoid = etContent.getText().toString();

if (titleVoid.equals("") || contentVoid.equals("")) {

Toast.makeText(NoteNew.this, “天启提示:标题或内容为空”, Toast.LENGTH_SHORT).show();

} else {

ToDatabase(); //插入数据库

Toast.makeText(NoteNew.this, “天启提示:便签保存成功”, Toast.LENGTH_SHORT).show();

finish();

}

}

}

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.note_new_menu, menu);

return true;

}

@Override

public boolean onOptionsItemSelected(MenuItem item) {

int id = item.getItemId();

if (id == R.id.action_exit) {

Intent intent = new Intent(Intent.ACTION_MAIN);

intent.addCategory(Intent.CATEGORY_HOME);

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

startActivity(intent);

android.os.Process.killProcess(android.os.Process.myPid());

return true;

} else if (id == R.id.action_about) {

Intent intent = new Intent(this, About.class);

startActivity(intent);

return true;

}

return super.onOptionsItemSelected(item);

}

public final int ToDatabase() {

String title = etTitle.getText().toString();

String content = etContent.getText().toString();

标签:note,db,NotePad,NOTE,cursor,new,Android,安装包,COL
来源: https://blog.csdn.net/m0_65145219/article/details/122214045

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有