无法更新查询Android
这不是错误,但我似乎无法更新我的表活动 我找不出这些说法有什么不对。这些值没有问题无法更新查询Android,android,Android,这不是错误,但我似乎无法更新我的表活动 我找不出这些说法有什么不对。这些值没有问题 goal_id = Integer.parseInt(extras.getString("goalid")); int i=0; Activities act = new Activities(goal_id,activityname.getText().toString(),Integer.parseInt(days.getText().toString()),i,false); dbhandler.updat
goal_id = Integer.parseInt(extras.getString("goalid"));
int i=0;
Activities act = new Activities(goal_id,activityname.getText().toString(),Integer.parseInt(days.getText().toString()),i,false);
dbhandler.updateActivty(act);
//更新活动
public int updateActivty(Activities act) {
SQLiteDatabase db = dbhandler.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(MyDBHandler.COLUMN_ACTIVITY_NAME, act.getActivityName());
values.put(MyDBHandler.COLUMN_DAYS, act.getDays());
values.put(MyDBHandler.COLUMN_NO_OF_TASKS, act.getNoOfTasks());
values.put(MyDBHandler.COLUMN_COMPLETE, act.getComplete());
// updating row
return db.update(MyDBHandler.TABLE_ACTIVITIES, values, MyDBHandler.COLUMN_ID + " = ?",
new String[] { String.valueOf(act.getId()) });
}
从未调用UpdateActivity方法。使用事件总线将数据活动发送到活动。如果我是你,我会做更多的工作,并执行以下操作: 通过搜索该id的值,尝试查看数据库中是否有数据: 下一步: 您创建的适配器可以从任何地方访问: 您的行将如下所示: 接下来,您将实现如下内容
MyRow implements IRow
{
public(to be accessed from outside upon creation) static final String COLUMN_ID = "_id";
public static final string COLUMN_VALUE = "value";
//here you do your implementation, with columns and stuff like that.
//Of course you need to take care of the creation of tables
update(SqliteDatabase db){//TODO}
insert(SqliteDatabase db){//TODO}
delete(SqliteDatabase db){//TODO}
//for update/delete/insert you can here implement the values assemble method.
}
正如您所注意到的,YourTable在本例中被称为MyColumn,它包含一些列,这些列通常是MyRow的一部分,以便在更新值时可以访问这些列。
基本上,您只需创建表就可以了。
这在3-4个项目中对我有效,没有任何错误。
我更喜欢这种方式,因为在传递字符串时,很多事情都可能出错。为什么要更新?另外,您通常会将数据传递给适配器,适配器会访问udpating数据的一部分。嗯,我会传递新值。db.update的返回值是多少?db.update方法返回s值如果更新成功,则返回long值>0如果不成功,则返回
MyAdapter implements IMyAdapter
{
@Override
public boolean insert(IRow row){
boolean success = false;
synchronized (lock) {
openIfDatabaseIsClosned();//here you get the writeable database and store it somewhere(I do it for multiple databases).
try {
row.insert(getDB());
success = true;
} catch (Exception e) {
Log.e(TAG, "Error:" + e.getMessage(), e);
}
}
return success;
}
@Override
public boolean update(IRow row) {
boolean success = false;
synchronized (lock) {
openDatabaseIfClosed();
try {
row.update(getDatabase());
success = true;
} catch (Exception e) {
Log.e(TAG, "Your error message:" + e.getMessage(), e);
}
}
return success;
}
}
interface IRow
{
void insert(SqliteDatabase db);
void update(SqliteDatabase db);
void delete(SqliteDatabase db);
void find(SqliteDatabase db);
}
MyRow implements IRow
{
public(to be accessed from outside upon creation) static final String COLUMN_ID = "_id";
public static final string COLUMN_VALUE = "value";
//here you do your implementation, with columns and stuff like that.
//Of course you need to take care of the creation of tables
update(SqliteDatabase db){//TODO}
insert(SqliteDatabase db){//TODO}
delete(SqliteDatabase db){//TODO}
//for update/delete/insert you can here implement the values assemble method.
}