没有类型参数的乐趣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