Tag: 领域

如何实现一个延迟加载recyclerView适配器,像使用kotlin的realm recyclerView适配器

我需要实现一个recyclerView,显示我的查询解析,所以我已经做到了: private class Pagination extends RecyclerView.OnScrollListener{ @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); visibleItemCount = manager.getChildCount(); totalItemCount = manager.getItemCount(); firstVisibleItemPosition = manager.findFirstVisibleItemPosition(); if (!isLoading && !isLastPage) { if ((visibleItemCount + firstVisibleItemPosition) >= totalItemCount && firstVisibleItemPosition >= 0 && totalItemCount >= PAGINATION) { isLoading = true; new Handler().postDelayed(new Runnable() { […]

在Kotlin项目中应用Realm插件会导致编译错误

我想添加Realm到一个Android项目,我已经添加了项目级别的classpath依赖项,但在我的模块的build.gradle文件中的apply plugin: 'realm-android'行导致下面的生成错误: Error:Execution failed for task ':data:compileDebugAndroidTestJavaWithJavac'. java.lang.NoClassDefFoundError: org/jetbrains/kotlin/annotation/AnnotationProcessorWrapper 如果没有这一行,应用程序的构建和运行良好,它里面没有Realm代码。 项目级别build.gradle: allprojects { repositories { jcenter() mavenCentral() } } buildscript { ext.kotlin_version = '1.0.6' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "io.realm:realm-gradle-plugin:2.3.0" } } task clean(type: Delete) { delete rootProject.buildDir } 模块build.gradle: apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: […]

当我添加将RealmObject扩展到我的项目的ChatInformation kotlin类时,无法建立项目,错误在哪里?

这是我的ChatInformation kotlin类: open class ChatInformation( var Id: Int = 0, var TopicId: Int = 0, var CreateTime: String? = null, var StartTime: String? = null, var EndTime: String? = null, var StatusId: Int = 0, var Duration: String? = null, var TeacherId: String = "", var LearnerId: String = "", var SubjectName: String = "", […]

Kotlin没有领域的吸气二传手

我想创建一个没有领域的getter和setter。 目前我有这个功能: /** Only the color component will be considered, alpha has no effect */ fun setCircleColor(@ColorInt color : Int){ circlePaint.color = ColorUtils.setAlphaComponent(color, circlePaint.alpha) } 理想情况下,我想有这样的事情 circleColor: @ColorInt Int get(){ return circlePaint.color set(value){ circlePaint.color = ColorUtils.setAlphaComponent(color, circlePaint.alpha) } 正如你所看到的,我不想在一个var中存储circleColor,但是能够调用 myView.color = 0xFFaaaaaa而不是myView.setColor(0xFFaaaaaa) 。 这可能吗?

Kotlin扩展功能:未解决的参考

我试图创建这个扩展功能: fun <T : RealmObject> Realm.query(myClass : KClass<T>) { RealmQuery.createQuery(this, myClass::class.java) } 这不会编译。 编译器说:“无法解析的引用:myClass”,当我写 myClass::class.java 但是,如果我这样做: fun <T : RealmObject> Realm.query(myClass : Class<T>) { RealmQuery.createQuery(this, myClass) } 它完美的作品! 我不明白为什么。

Kotlin和@Transient

一堂课: open class MessageDTO : RealmObject, Serializable { @PrimaryKey @SerializedName("message_id") var messageId: String? = null @SerializedName("chat") var chat: String? = null @SerializedName("chat_type") var chatType: String? = null @SerializedName("content") var content: ContentDTO? = null @SerializedName("created") var created: Date? = null @SerializedName("from") var from: String? = null @SerializedName("important") var important: Boolean? = null @SerializedName("is_first") var isFirst: Boolean? […]

Kotlin懒惰的用法

我目前在我的应用程序中使用Realm,为了确保正确管理Realm实例,我在基本Activity中引入了一个像这样的变量: protected val realm: Realm by lazy { Realm.getDefaultInstance() } 然后在onDestroy我这样做: override fun onDestroy() { super.onDestroy() realm.close() } 然后我意识到这是一种浪费。 如果当前活动不使用领域,它将打开并立即在onDestroy关闭。 所以我更新到这个: private var usedRealm = false protected val realm: Realm by lazy { usedRealm = true Realm.getDefaultInstance() } override fun onDestroy() { super.onDestroy() if (usedRealm) { realm.close() } } 有没有办法做到这一点,没有额外的标志?

基本领域+ Kotlin:RealmObject不设置传递值

最近我开始和Kotlin一起使用Realm,但是我无法在DB上做一个简单的插入。 以下是我正在使用的代码: 模型 open class User : Serializable, RealmObject() { open var user_id: Long = 0 open var name: String = "" open var nickname: String = "" open var thumbnail: String = "" open var password: String = "" open var email: String = "" open var token: String = "" open var country_code: […]

如何使用Realm的方法与Kotlin

我正在尝试做类似的事情: val barcodes = arrayOf("123", "456", "789") realm.where(Product::class.java).in("barcode", barcodes).findAll() 但是“in”是一个Kotlin函数,我无法访问RealmQuery对象的in(String filedName,String [] values)方法。 目前我有一个java类来完成这个工作,并返回结果,但我想知道是否有一个更优雅的解决方法呢?

领域查询通知不使用Kotlin触发

我无法使用Kotlin在Android中触发Realm Query Notifications。 我已经尝试完整(1)和lambda(2)语法分开: object DataService { val realm: Realm = Realm.getDefaultInstance() var allDogs: RealmResults<Dog> = realm.where(Dog::class.java).findAll() fun start() { // (1) allDogs.addChangeListener(object: RealmChangeListener<RealmResults<Dog>> { override fun onChange(element: RealmResults<Dog>?) { print("Ping?") } }) // (2) allDogs.addChangeListener { // This listener doesn't fire when I create managed the Dog object below print("Ping?") } realm.executeTransaction { realm.createObject(Dog::class.java) […]