Android 如何更新我的EditText值?

Android 如何更新我的EditText值?,android,sql-update,android-sqlite,Android,Sql Update,Android Sqlite,我是android新手,因为我正在尝试使用上下文菜单项“编辑”更新数据。使用编辑,我将进入EditText布局,然后我将按更新说明,但它不会更新EditText数据 我的代码数据库: public void updateNote(String filename, String filedata, String duedate){ SQLiteDatabase db = this.getWritableDatabase(); ContentValues updatenote =

我是android新手,因为我正在尝试使用上下文菜单项“编辑”更新数据。使用编辑,我将进入
EditText
布局,然后我将按更新说明,但它不会更新
EditText
数据

我的代码数据库:

public void updateNote(String filename, String filedata, String duedate){

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues updatenote = new ContentValues();
    updatenote.put(Col_File_Name, filename);
    updatenote.put(Col_File_Data, filedata);
    updatenote.put(Col_Due_Date, duedate);

    db.update(Table_Notepad, updatenote, Col_ID + "=?", null);
    db.close();
}
活动:

case R.id.Save:


    String get_title = Title_Edit.getText().toString();
    String get_content = Content_Edit.getText().toString();
    String get_duedate = duedatetext.getText().toString();

    if(!get_title.equals("") || !get_content.equals(""))
    {


     if (!isEdit) {
            //if it isn't edit mode we just add a new note to db

             Database_Notepad db = new Database_Notepad(Add_Task.this);

             db.Create_Note(get_title, get_content, get_duedate);

        } else {
            //if this is edit mode, we just update the old note
             Database_Notepad db = new Database_Notepad(Add_Task.this);

             db.updateNote(get_title, get_content, get_duedate);

            db.close();
        }

    }
请建议,我想我需要更正数据库代码。请建议。感谢在
updateNode()
中,您需要更改此更新或插入值:

public void updateNote(long rowId, String filename, String filedata, String duedate){

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues updatenote = new ContentValues();
    updatenote.put(Col_File_Name, filename);
    updatenote.put(Col_File_Data, filedata);
    updatenote.put(Col_Due_Date, duedate);

    if (rowId >=0)
        db.update(Table_Notepad, updatenote, Col_ID + "=?", new String[] {""+rowId});
    else
        db.insert(Table_Notepad, null, updatenote);
    db.close();
}
然后,如果您正在创建一个新便笺,您可以调用:

updateNode(-1,文件名,文件数据,日期)

如果您正在更新现有的,则必须输入ID:

updateNode(noteRowId、文件名、文件数据、截止日期)


来源:检查这些。

需要在最后一个参数中传递要更新的行id

db.update(Table_Notepad, updatenote, Col_ID + "=?", new String[]{id});

快乐编码

您的函数
updateNote
需要您想要更新的记录ID

public void updateNote(int-id、字符串文件名、字符串文件数据、字符串日期){

反而

public void updateNote(字符串文件名、字符串文件数据、字符串日期){

并比较您的整个记录所使用的id,它将检查并更新您的特定记录,更改您的函数,如下所示:

public void updateNote(int id, String filename, String filedata, String duedate){

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues updatenote = new ContentValues();
    updatenote.put(Col_File_Name, filename);
    updatenote.put(Col_File_Data, filedata);
    updatenote.put(Col_Due_Date, duedate);

    db.update(Table_Notepad, updatenote,  "rowid= "+id,, null);// rowid or name of your id column
    db.close();
}
并将
id
与其他参数一起传递

使用

updateNote(id,get_title,get_content,get_duedate)

反而

updateNote(获取标题、获取内容、获取日期)


您需要知道要更新数据库中的哪一行,因此在这种情况下使用ID作为主键是很好的。检查此链接,它可能会帮助您确定要更新的记录的ID或位置。@Shweta如果用户想要修改现有注释,则您需要以某种方式传入行ID。或者您将ID默认设置为-1,哪个crea这是一个新的音符。