基于android的日记本开发内容摘要:

(删除 , new () { @Override public void onClick(DialogInterface dialog, int which) { ()。 (getListView().getItemIdAtPosition(position))。 updateListView()。 ()。 } })。 ().show()。 // show(x)。 //弹出对话框 } } 3. DbAdapter 类为自定义的重要的数据库处理类 , 用来管理数据库 , 对数据库的所有操作都封装在这个类中 , 实现数据封装。 主要方法如下:  private static final String DATABASE_CREATE: 创建 diary 表 ;  open() throws SQLException:打开数据库;  updateDiary:更新 diary 表;  getAllNotes: 得到所有日记 ;  deleteDiary: 删除一个 选定日记 ;  getDiary(long rowId) throws SQLException: : 得到指定日记 ; 主要代码: //创建 diary 表 private static final String DATABASE_CREATE = create table diary + (_id integer primary key autoincrement, + title text not null, body text not null, created text not null)。 //声明初始值 private static final String DATABASE_NAME =。 private static final String DATABASE_TABLE_DIARY = diary。 private static final int DATABASE_VERSION = 1。 private final Context mCtx。 //数据库类 private static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION)。 } public void onCreate(SQLiteDatabase db) { (DATABASE_CREATE)。 (create, 111)。 } public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { (DROP TABLE IF EXISTS diary)。 8 (DROP TABLE IF EXISTS course)。 onCreate(db)。 } } public DbAdapter(Context ctx) { = ctx。 } //打开数据库 public DbAdapter open() throws SQLException { mDbHelper = new DatabaseHelper(mCtx)。 mDb = ()。 (open, 222)。 return this。 } //关闭数据库 public void closeclose() { (close, asdf)。 ()。 } //创建一个日记 public long createDiary(String title, String body) { ContentValues initialValues = new ContentValues()。 (KEY_TITLE, title)。 (KEY_BODY, body)。 Calendar calendar = ()。 String created = () + 年 + () + 月 + () + 日。 (KEY_CREATED, created)。 return (DATABASE_TABLE_DIARY, null, initialValues)。 } //删除选定日记 public boolean deleteDiary(long rowId) { return (DATABASE_TABLE_DIARY, KEY_ROWID + = + rowId, null) 0。 } //得到所有日记 public Cursor getAllNotes() { return (DATABASE_TABLE_DIARY, new String[] { KEY_ROWID, KEY_TITLE, KEY_BODY, KEY_CREATED }, null, null, null, null, null)。 } //得到制定日记 public Cursor getDiary(long rowId) throws SQLException { Cursor mCursor = (true, DATABASE_TABLE_DIARY, new String[] { KEY_ROWID, KEY_TITLE, KEY_BODY, KEY_CREATED }, KEY_ROWID + = + rowId, null, null, null, null, null)。 9 if (mCursor != null) { ()。 } return mCursor。 } //更新 diary 表 public boolean updateDiary(long rowId, String title, String body) { ContentValues args = new ContentValues()。 (KEY_TITLE, title)。 (KEY_BODY, body)。 Calendar calendar = ()。 String created = () + 年 + () + 月 + () + 日。 (KEY_CREATED, created)。 return (DATABASE_TABLE_DIARY, args, KEY_ROWID + = + rowId, null) 0。 } } package。 4. Diary_activity 类和 DiaryEditActivity 类实现日记的创建和删除。 主要方法如下 :  updateListView(): 更新当前的 listacvitity;。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。