没有类型参数的乐趣findViewById(p0:Int):视图
我试图像这样在Kotlin上声明一个imageView:
view.findViewById<ImageView>(R.id.tabImage)).setImageResource(selector)
但我总是这个错误,
Error:(30, 27) No type arguments expected for fun findViewById(p0: Int): View!
有人可以帮助PLZ吗? 谢谢
应该是这样的
ImageView imageView = view.findViewById<ImageView>(R.id.tabImage) imageView.setImageResource(selector)
ImageView imageView = view.findViewById(R.id.tabImage) as ImageView imageView.setImageResource(selector)
尝试这个
private var aImageView : ImageView? = null aImageView = findViewById(R.id.imageview) as ImageView
- Kotlin anko通用选择器在提供的示例中不起作用
- 无法使用Android从测试来源访问内部组件
- 将数据模型映射到域模型的简单方法
- 未解决的参考:文本 – Android Studio + Kotlin(findViewById故障?)
- 指定为非null的参数在ArrayAdaper中为null
- Kotlin kotlinClass.class.getName()不能返回包名,而只能返回简单的类名
- 未解决的参考:LinearLayoutManager / RecyclerView
- 得到未解决的参考:将java转换为kotlin时的setText
- 无法在Android Studio 2.0中安装或卸载任何插件