資源描述:
《基于Andriod平臺(tái)的安卓記事本程序源碼》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、DatabaseHelper.javapackagecom.notepad.namespace;importandroid.content.Context;importandroid.database.sqlite.SQLiteDatabase;importandroid.database.sqlite.SQLiteDatabase.CursorFactory;importandroid.database.sqlite.SQLiteOpenHelper;publicclassDatabaseHelperextendsSQLiteOpenHelper{privateStringt
2、ableName="record";privateContextmContext=null;privateStringsql="createtableifnotexists"+tableName+"(_idintegerprimarykeyautoincrement,"+"titlevarchar,"+"contenttext,"+"timevarchar)";publicDatabaseHelper(Contextcontext,Stringname,CursorFactoryfactory,intversion){super(context,name,factory,ver
3、sion);//TODOAuto-generatedconstructorstub}@OverridepublicvoidonCreate(SQLiteDatabasedb){//TODOAuto-generatedmethodstub//創(chuàng)建表db.execSQL(sql);}@OverridepublicvoidonUpgrade(SQLiteDatabasedb,intoldVersion,intnewVersion){//TODOAuto-generatedmethodstub}}DatabaseManage.javapackagecom.notepad.namespa
4、ce;importjava.util.Date;importandroid.content.ContentValues;importandroid.content.Context;importandroid.database.Cursor;importandroid.database.sqlite.SQLiteDatabase;importandroid.database.sqlite.SQLiteException;importandroid.util.Log;publicclassDatabaseManage{privateContextmContext=null;priv
5、ateSQLiteDatabasemSQLiteDatabase=null;//用于操作數(shù)據(jù)庫(kù)的對(duì)象privateDatabaseHelperdh=null;//用于創(chuàng)建數(shù)據(jù)庫(kù)的對(duì)象privateStringdbName="notepad.db";privateintdbVersion=1;publicDatabaseManage(Contextcontext){mContext=context;}/***打開數(shù)據(jù)庫(kù)*/publicvoidopen(){try{dh=newDatabaseHelper(mContext,dbName,null,dbVersion);if(dh=
6、=null){Log.v("msg","isnull");return;}mSQLiteDatabase=dh.getWritableDatabase();//dh.onOpen(mSQLiteDatabase);}catch(SQLiteExceptionse){se.printStackTrace();}}/***關(guān)閉數(shù)據(jù)庫(kù)*/publicvoidclose(){mSQLiteDatabase.close();dh.close();}//獲取列表publicCursorselectAll(){Cursorcursor=null;try{Stringsql="select*f
7、romrecord";cursor=mSQLiteDatabase.rawQuery(sql,null);}catch(Exceptionex){ex.printStackTrace();cursor=null;}returncursor;}publicCursorselectById(intid){//Stringresult[]={};Cursorcursor=null;try{Stringsql="select*fromrecordwhere_id='"+id+"'";cursor=m