数据库记录未更新android studio,sql-lite

时间:2018-09-26 07:59:38

标签: java android sqlite android-studio

有人可以帮我吗?我的记录没有更新。 我想edittext保持不变,但不太确定。

如何更改在编辑文本中放置的视图值,以更改为更新编辑文本时的值。 希望对此有所帮助 谢谢。

DatabaseManager

set.seed(1234)
# calculate days-to-remission:
ALL.pdat <- pData(ALL)
date.cr.chr <- as.character(ALL.pdat$date.cr)
diag.chr <- as.character(ALL.pdat$diagnosis)
date.cr.t <- strptime(date.cr.chr,"%m/%d/%Y")
diag.t <- strptime(diag.chr,"%m/%d/%Y")
ALL.pdat$D2R <- as.numeric(date.cr.t - diag.t)
# prepare the data structures:
ALL.exprs <- exprs(ALL)[,!is.na(ALL.pdat$D2R)]
ALL.pdat <- ALL.pdat[!is.na(ALL.pdat$D2R),]
n.xval <- 5
s2.xval <- numeric()
xval.grps <- sample(1:dim(ALL.pdat)[1]%%n.xval+1)
# run over each cross-validation:
for ( i.xval in 1:n.xval ) {
min.pval <- 1.0
min.id <- NA
train.exprs <- ALL.exprs[,xval.grps!=i.xval]
train.d2r <- ALL.pdat[xval.grps!=i.xval,"D2R"]
# evaluate each gene in the training dataset to find the one
# most associated with the outcome:
for( i in 1:dim(train.exprs)[1]) {
###for( i in 1:100 ) {
p.val <- anova(lm(train.d2r~train.exprs[i,],))[1,"Pr(>F)"]
if ( p.val < min.pval ) {
min.pval <- p.val
min.id <- i
}
}
# print the gene found:
cat(rownames(train.exprs)[min.id],min.pval,fill=T)
# refit the model for best gene found on training dataset:
best.lm.xval <- lm(train.d2r~train.exprs[min.id,])
# calculate predictions on test dataset:
test.exprs <- ALL.exprs[,xval.grps==i.xval]
test.d2r <- ALL.pdat[xval.grps==i.xval,"D2R"]
test.pred <- predict(
best.lm.xval,data.frame(t(test.exprs),test.d2r)
)
# accumulate squared errors of prediction:
s2.xval <- c(s2.xval,(test.pred-test.d2r)^2)
}

以上是本活动中使用的数据库的一部分。

活动main.java

   public Cursor selectRow(String ID) {
        String query = "Select * from " + TABLE_NAME + " where studentID = " + ID;
        Cursor cursor = db.rawQuery(query, null);
        return cursor;

    }

    public boolean updateData(String id, String fn, String ln, String ge, String cs, String a, String loc) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("studentID", id);
        contentValues.put("first_name", fn);
        contentValues.put("last_name", ln);
        contentValues.put("gender", ge);
        contentValues.put("course_study", cs);
        contentValues.put("age", a);
        contentValues.put("location", loc);
        db.update(TABLE_NAME, contentValues, "studentID = ?", new String[]{id});

        return true;
    }

我尝试过使用按钮来设置数据,但它仍然保持不变。

1 个答案:

答案 0 :(得分:0)

很抱歉,我们没有读代码,如果有帮助,请拿出示例 只是逻辑。

public long updateNote(NoteModel noteModel) {
    if (LOG_DEBUG) UtilLogger.showLogUpdate(TAG, noteModel, noteModel.getRow_pos());
    long updatedRow = 0;

    try {

        ContentValues contentValues = new ContentValues();
        contentValues.put(DBSchema.DB_TITLE, noteModel.getTitle());
        contentValues.put(DBSchema.DB_IMAGE_PATH, noteModel.getImgUriPath());
        contentValues.put(DBSchema.DB_SUB_TEXT, noteModel.getSub_text());
        contentValues.put(DBSchema.DB_CREATE_DATE, noteModel.getCreateDate());
        contentValues.put(DBSchema.DB_UPDATE_DATE, noteModel.getUpdateDate());
        contentValues.put(DBSchema.DB_SCHEDULED_TIME_LONG, noteModel.getScheduleTimeLong());
        contentValues.put(DBSchema.DB_SCHEDULED_TIME_WHEN, noteModel.getScheduledWhenLong());
        contentValues.put(DBSchema.DB_SCHEDULED_TITLE, noteModel.getScheduledTitle());
        contentValues.put(DBSchema.DB_IS_ALARM_SCHEDULED, noteModel.getIsAlarmScheduled());
        contentValues.put(DBSchema.DB_IS_TASK_DONE, noteModel.getIsTaskDone());
        contentValues.put(DBSchema.DB_IS_ARCHIVED, noteModel.getIsArchived());


        updatedRow = mSqLiteDatabase.updateWithOnConflict(
                DBSchema.DB_TABLE_NAME,
                contentValues,
                DBSchema.DB_ROW_ID + " =?", new String[]{String.valueOf(noteModel.get_id())}, mSqLiteDatabase.CONFLICT_REPLACE);

        return updatedRow;

    } catch (SQLException e) {
        e.printStackTrace();
    }
    return updatedRow;
}

然后移动光标

public Cursor getCursorForAlarmScheduled(String passAlarmScheduledStatus) {
    if (LOG_DEBUG)
        Log.w(TAG, " pick all record with alarmScheduled 1  : " + passAlarmScheduledStatus);
    return mSqLiteDatabase.rawQuery(DBSchema.DB_SELECT_ALL +
            " WHERE " + DBSchema.DB_IS_ALARM_SCHEDULED + " = " + passAlarmScheduledStatus, null);
}

然后提取

 //common operation for all,
public static List<NoteModel> extractCommonData(Cursor cursor, List<NoteModel> noteModelList) {
    noteModelList = new ArrayList<>();

    if (LOG_DEBUG) Log.i(TAG, "inside extractCommonData()");
    if (cursor != null) {
        if (cursor.moveToFirst()) {
            do {
                NoteModel noteModel = new NoteModel();

                noteModel.set_id(cursor.getInt(cursor.getColumnIndex(DBSchema.DB_ROW_ID)));
                noteModel.setTitle(cursor.getString(cursor.getColumnIndex(DBSchema.DB_TITLE)));
                noteModel.setImgUriPath(cursor.getInt(cursor.getColumnIndex(DBSchema.DB_IMAGE_PATH)));
                noteModel.setSub_text(cursor.getString(cursor.getColumnIndex(DBSchema.DB_SUB_TEXT)));
                noteModel.setCreateDate(cursor.getLong(cursor.getColumnIndex(DBSchema.DB_CREATE_DATE)));
                noteModel.setUpdateDate(cursor.getLong(cursor.getColumnIndex(DBSchema.DB_UPDATE_DATE)));
                noteModel.setScheduleTimeLong(cursor.getLong(cursor.getColumnIndex(DBSchema.DB_SCHEDULED_TIME_LONG)));
                noteModel.setScheduledWhenLong(cursor.getLong(cursor.getColumnIndex(DBSchema.DB_SCHEDULED_TIME_WHEN)));
                noteModel.setScheduledTitle(cursor.getString(cursor.getColumnIndex(DBSchema.DB_SCHEDULED_TITLE)));
                noteModel.setIsAlarmScheduled(cursor.getInt(cursor.getColumnIndex(DBSchema.DB_IS_ALARM_SCHEDULED)));
                noteModel.setIsTaskDone(cursor.getInt(cursor.getColumnIndex(DBSchema.DB_IS_TASK_DONE)));
                noteModel.setIsArchived(cursor.getInt(cursor.getColumnIndex(DBSchema.DB_IS_ARCHIVED)));
                noteModelList.add(noteModel);

            } while (cursor.moveToNext());
        }
        cursor.close();

    }
    return noteModelList;
}

同样,我没有看过,只是从我的旧样本中复制而来 请找到需要的人,欢呼声