Android Kotlin ImageView绑定

时间:2017-04-18 12:02:51

标签: android binding kotlin

如何将数据绑定到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

1 个答案:

答案 0 :(得分:1)

功能loadPhotoFilePath应该在课外,将其置于class OrderInfoFragment之上。

或者另一种方法是将其注释为@JvmStatic