3つのボタン(OK、Alterar、Delete)があるダイアログがあるので、Alterarをクリックすると、別のアクティビティに移動して値を変更しますが、変更するコードがわかりません。私は2つしか知りません。それは.put/.insertと.deleteです。では、変更はどうですか?
2行:nome、telefone
了解しました。これはあなたの編集に対する答えです。行を含むテーブルの名前がPersonであるとします。ここで、「MrSmith」という人の電話番号を123456789に変更します。
まず、変更する新しい値を入力します。
// Values to insert
ContentValues dataToInsert = new ContentValues();
dataToInsert.put("name", "MrSmith");
dataToInsert.put("phone", 123456789);
名前を元に戻す必要はないかもしれませんが、少し前にこれを行いました。自分で試すことができます:)では、これらをデータベースに挿入しましょう!
// We want to update the row where the name is "MrSmith"
String where = "id=?";
String[] whereArgs = { "MrSmith" };
?ここで、db.update(...)を実行すると、文字列がMrSmithに置き換えられます。これで、SQLは、更新する行と更新するデータを認識します。コミットしましょう!
// Update table Person where the row name is "MrSmith" with the values entered
// in ContentValues!
db.update("Person", dataToInsert, where, whereArgs);
これがお役に立てば幸いです。それ以外の場合は、SQLステートメントがどのように実行されるかを確認する必要があります。
編集機能
public void editdata(int id,String name) { db.execSQL("update person set name=""+name+"' where id="+id);
}
通話機能
editdata(id,"テスト");