我正在尝试在Android中实现Realm。有没有办法像SQLite 中的数据库处理程序一样实现?找到的每个样本都在UI中,只需按一下按钮。单独的数据库文件没有纯实现。
我有一个Database Handler类,如下所示:
public class DatabaseHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "MyTrain";
private static final String TABLE_ROUTE = "Route";
private static final String COLUMN_ID = "Id";
private static final String COLUMN_ROUTENAME = "RouteName";
private static final String COLUMN_REMARKS = "Remarks";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_ROUTE_TABLE = "CREATE TABLE IF NOT EXISTS "
+ TABLE_ROUTE + "("+COLUMN_ID+" INTEGER PRIMARY KEY,"
+ COLUMN_ROUTENAME+" TEXT,"+COLUMN_REMARKS+" TEXT)";
db.execSQL(CREATE_ROUTE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_ROUTE);
onCreate(db);
}
//to insert data
public void AddRoute(int Id, String RouteName, String Remarks)
{
SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COLUMN_ID, Id);
contentValues.put(COLUMN_ROUTENAME, RouteName);
contentValues.put(COLUMN_REMARKS, Remarks);
sqLiteDatabase.insert(TABLE_ROUTE, COLUMN_ID, contentValues);
sqLiteDatabase.close();
}
//Other CRUD Operation Functions lies here....
}
我想制作专门用于数据库内容的类似函数和数据库处理程序类。
那么,我如何在Realm数据库中实现类似的功能..