Android Kotlin ImageView绑定
如何将数据绑定到kotlin中的imageview?
<ImageView app:photoFilePath="@{item.photoFilePath}" android:layout_width="60dp" android:layout_height="60dp" />
这是我的班级,我已经实施:
class OrderInfoFragment : BaseDialogFragment() { private lateinit var mOrderItem: OrderItem override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val inflater = activity.layoutInflater val binding = DataBindingUtil.inflate<FragmentOrderInfoBinding>( inflater, R.layout.fragment_order_info, null, false) val view = binding.root binding.item = mOrderItem } @BindingAdapter("bind:photoFilePath") fun loadPhotoFilePath(imageView: ImageView, path: String) { } }
我已经尝试在伴侣对象中使用loadPhotoFilePath
。
函数loadPhotoFilePath
应该超出类,将它放在class OrderInfoFragment
类的上面。
或者另一种方法是将其注释为@JvmStatic