i create custom attribute use by BindingAdapter
,but it unable to use in layout
BindingAdapter
@BindingAdapter("android:killAble")
fun View.setKillAble(killAble: Boolean) {
this.isEnabled = killAble
}
layout
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/et_height"
android:killAble="true"
android:layout_marginTop="32dp"
app:layout_constraintTop_toBottomOf="@+id/et_name"
android:layout_marginStart="16dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginRight="16dp"
/>
HomeFragment.kt
class HomeFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val binding: FragmentHomeBinding = DataBindingUtil.inflate(inflater,
R.layout.fragment_home, container, false)
val rootView = binding.root
val viewmodel=ViewModelProviders.of(this).get(HomeViewModel::class.java)
binding.lifecycleOwner = this
binding.viewModel = viewmodel
return rootView
}
}
please help me
You must use the data binding syntax:
android:killAble="@{true}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With