2017-04-18 26 views
0

kotlinの画像ビューにデータをバインドするにはどうすればよいですか?Android 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

機能loadPhotoFilePathは、クラス外である必要があります。class OrderInfoFragmentより上に配置してください。

または別の方法では、@JvmStatic

と注釈を付けることです