Android Room persistence library @Update not working

前端 未结 3 1614
南旧
南旧 2021-02-05 09:42

I am trying to update my database via new android room library, but it is not working. Here it is my approach

@IgnoreExtraProperties
@Entity(tableName = CarModel         


        
3条回答
  •  攒了一身酷
    2021-02-05 10:04

    The update means you fetch a CarModel which is already in the database and after updating this CarModel you return the new values to the Database, except the Id you return the same Id

    what to do

    you need for example a global variable of type CarModel and implement set functions in the CarModel

    In MainActivity assignt the fetched CarModel to the global variable and use the set functions to update the values of member variables of the CarModel

    then pass this global variable to the update function in MainActivity

    I have example in my Github like this

提交回复
热议问题