小编Mar*_*vin的帖子

如何使用jackson反序列化到Kotlin集合

示例代码我想要的:

data class D(val a: String, val b: Int)
val jsonStr = """[{"a": "value1", "b": 1}, {"a": "value2", "b":"2}]"""
// what I need
val listOfD: List<D> = jacksonObjectMapper().whatMethodAndParameter?
Run Code Online (Sandbox Code Playgroud)

json jackson kotlin

17
推荐指数
2
解决办法
2万
查看次数

如何在Anko DSL中引用其他视图?

我在我的Android项目中使用Anko,但我不知道它如何引用我在DSL中创建的子视图,当引用的视图不在我引用它的同一级别时.

以下代码有效:

alert {
    customView {
        val input = textInputLayout {
            editText {
                hint = "Name"
                textColor =resources.getColor(R.color.highlight)
            }
        }


        positiveButton("OK") { "${input.editText.text}" }
    }
}.show()
Run Code Online (Sandbox Code Playgroud)

但以下代码不起作用:

alert {
    customView {
        val vertical = verticalLayout {
            textView {
                text = "Edit device name"
                textColor = resources.getColor(R.color.highlight)
                textSize = 24F
            }
            val input = textInputLayout {
                editText {
                    hint = "Name"
                    textColor = resources.getColor(R.color.highlight)
                }
            }
        }

        positiveButton("OK") { "${vertical.input.editText.text}" }  // Cannot resolve "input"
    }
}.show()
Run Code Online (Sandbox Code Playgroud)

android kotlin anko

15
推荐指数
1
解决办法
2993
查看次数

ButterKnife没跟杰克合作?

我刚开始一个非常简单的项目,并尝试使用ButterKnife和Jack编译器,但似乎它们并不能很好地应对.

Gradle插件版本:2.2.0-alpha5

在我的模块build.gradle中我添加了:

compile 'com.jakewharton:butterknife:8.2.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.2.1'
Run Code Online (Sandbox Code Playgroud)

并且错误消息是:

Error:Execution failed for task ':app:transformJackWithJackForDebug'.
java.lang.AssertionError: java.lang.IllegalArgumentException
Run Code Online (Sandbox Code Playgroud)

我错过了什么,或者只是他们不兼容?

android android-layout android-studio butterknife jack-compiler

13
推荐指数
2
解决办法
1566
查看次数

RxJava和FasterXML是否有有效的proguard规则?

现在阻止我在生产中使用kotlin的唯一问题是我找不到正确的proguard文件.

我用过的:

1.Kotlin

2.Anko

3.Jackson-科特林模块

这是警告信息:

:app:proguardRelease
Warning: com.fasterxml.jackson.databind.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
Warning: rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.ConcurrentCircularArrayQueue: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.ConcurrentSequencedCircularArrayQueue: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.MpmcArrayQueueConsumerField: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.MpmcArrayQueueProducerField: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.MpscLinkedQueue: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.SpmcArrayQueueConsumerField: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.SpmcArrayQueueProducerField: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.SpscArrayQueue: can't …
Run Code Online (Sandbox Code Playgroud)

android proguard kotlin fasterxml rx-java

8
推荐指数
2
解决办法
7689
查看次数

如何在Android Studio中为Kotlin设置自动导入?

我只能在首选项中找到XML,Java和C/C++的自动导入选项,但如何在Android Studio中为Kotlin进行自动导入?

在此输入图像描述

更新: 大多数情况下,会自动添加import语句.但删除代码时,未使用的import语句永远不会自动清除.

intellij-idea kotlin android-studio

6
推荐指数
1
解决办法
1419
查看次数

为什么Kotlin不允许在主构造函数中使用任何代码?

使用代码流失时会造成不便

abstract class View {
    abstract fun findViewById(id: Int): View
    abstract fun setOnClickListener(listener: (View) -> Boolean)
}

class ViewHolder(itemView: View) {
    init {
        child1.setOnClickListener { false }
    }
    val child1 = itemView.findViewById(1)
    val child2 = itemView.findViewById(2)
}
Run Code Online (Sandbox Code Playgroud)

编译器抱怨说:

Kotlin: Variable 'child1' must be initialized
Run Code Online (Sandbox Code Playgroud)

所以我必须添加一个额外的功能,并在每次构建后调用它:

class ViewHolder(itemView: View) {
    val child1 = itemView.findViewById(1)
    val child2 = itemView.findViewById(2)

    fun bindEventHandlers() {
        child1.setOnClickListener { false }
    }
}

val vh = ViewHolder(v)
vh.bindEventHandlers()
Run Code Online (Sandbox Code Playgroud)

那么,有没有方便的方法来做这样的init?使用Android RecyclerView和ListView时经常会发生这种情况.

android kotlin

2
推荐指数
1
解决办法
157
查看次数

DataBindingComponents如何基于每个布局工作?

Android DataBinding库是我学习MVVM的迷人库。现在存在一个问题,即如何在基于布局的基础上将文本更新到UI之前播放动画。(不是BindingAdapter使用静态绑定适配器的全局布局的解决方案。)

从IO16视频中,我知道也许可以DataBindingComponentsetImageUrl示例一样使用它来实现这种效果,但是我找不到关于DataBindingComponents和BindingAdapter注释实例方法的工作方式的示例代码,有人可以提供有关此细节的信息吗?

== 更新2016-07-06 ==

我知道我可以使用带有自定义标签的静态绑定适配器,但这不是我想要的。

== 更新2017-08-04 ==我不知道为什么这个问题被标记为重复,如果您知道android数据绑定,则另一个问题完全不同。只是不知道如何删除重复标记,因此请在此处进行编辑。

data-binding android android-databinding

1
推荐指数
1
解决办法
714
查看次数