小编Sur*_*wal的帖子

RecyclerView与ListView

来自android开发人员(创建列表和卡片):

RecyclerView小部件是ListView的更高级和灵活的版本.

好吧,这听起来很酷,但是当我看到这个示例图片时,我对两者之间的区别感到非常困惑.

在此输入图像描述

ListView使用自定义适配器可以轻松创建上面的图片.

那么,在什么情况下应该使用RecyclerView

android listview android-recyclerview

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

启用 proguard 后无法访问 kotlin 类中使用的伴随对象

我有一个 Kotlin 类,在伴随对象中有一些变量。启用 proguard 后,变量不会被访问。

class Test{    
    ......    
    companion object {    
        const val USER_NAME = "user_name"    
        .....    
  }    
  .....    
}  
Run Code Online (Sandbox Code Playgroud)

Proguard 规则包括:-

-keep class kotlin.** { *; }    
-keep class kotlin.Metadata { *; }    
-dontwarn kotlin.**    
-keepclassmembers class **$WhenMappings {    
    <fields>;    
}    
-keepclassmembers class kotlin.Metadata {    
    public <fields>;    
    public <methods>;    
}    

-keepclassmembers class * {    
    static final % *;    
    static final java.lang.String *;    
}    
Run Code Online (Sandbox Code Playgroud)

proguard kotlin

7
推荐指数
3
解决办法
3415
查看次数

Kotlin:将对象转换为通用类

如何获取泛型类的类型并将对象转换为它?

我想使用这个函数来传递一个 Interface 类:

protected fun <T> getInteraction(): T {
        return when {
            context is T -> context
            parentFragment is T -> parentFragment as T
            else -> throw IllegalArgumentException("not implemented interaction")
        }
    }
Run Code Online (Sandbox Code Playgroud)

并像这样使用它:

 private var interaction: ISigninInteraction? = null

 override fun onAttach(context: Context?) {
        super.onAttach(context)
        interaction = getInteraction<ISigninInteraction>()

 }
Run Code Online (Sandbox Code Playgroud)

generics android interface fragment kotlin

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