Update record in database

0

I have a question, I would like to update a record of five of a database in SQLite and that the resulting list shows the four unregistered records next to the new record.

I'm getting involved and I do not know if it will be necessary to create several constructors. I created the class Modelo to call it when updating all the records but when I need only to modify one of them, the question arises.

public class Modelo {
    private int id;
    private String name;
    private String age;
    private String phone;
    private byte[] image;

    public Modelo(int id, String name, String age, String phone, byte[] image) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.phone = phone;
        this.image = image;
    }

I hope you can clarify something to me

    
asked by Fran 23.10.2018 в 19:50
source

1 answer

0

For that you have the update () method

You use your model

Modelo modeloBE = new Modelo();
modeloBE.id = "1";
modeloBE.name = "name";
modeloBE.age = "age";
modeloBE.phone = "phone";

create the ContentValues

ContentValues initialValues = new ContentValues();
initialValues.put("id", modeloBE.id);
initialValues.put("name", modeloBE.name);
initialValues.put("age", modeloBE.age);
initialValues.put("phone", modeloBE.phone);

you make the update to your table

   return mDb.update("NOMBRE DE LA TABLA", initialValues, "ACA PONES TU WHERE.", null);
    
answered by 23.10.2018 / 20:07
source