How to set primary key auto increment in realm android

后端 未结 8 620
眼角桃花
眼角桃花 2020-12-14 07:13

I want to set primary key auto increment for my table.

Here is my Class. I have set primary key but I want it to be auto increment primary key.

publ         


        
8条回答
  •  一整个雨季
    2020-12-14 07:47

    In Kotlin

    My Interfaces

    fun getRegistroIdentity(): Int
    

    My Method

    class RegistroOver(private val realm: Realm) : RegistroImplementation {
    
    override fun getRegistroIdentity(): Int {
        val registro = realm.where(Registro::class.java).max("id")
        val result: Int
        result = if (registro == null) {
            1
        } else {
            registro.toInt() + 1
        }
        return result
    }}
    

    :)

提交回复
热议问题