jack_the_beast
jack_the_beast

Reputation: 1971

Android: custom view data binding: bind values from system attrs.xml

I want to pass values like EditText's imeOption and inputType to a custom view (which contains an EditText) using @BindingAdapter so it can be customizable from the view that will be using it.

Ideally this would go:

@JvmStatic
@BindingAdapter("customEditText:imeOptions")
fun setImeOption(view: CustomEditText, inputVariable: Int) {
    view.binding.editText.imeOptions = inputVariable
}

and in xml:

<CustomEditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    customEditText:imeOptions="@{actionDone}"/>

but actionDone cannot be resolved. It there any way to do this?

Note: CustomEditText does not extend EditText, it's just a LinearLayout which contains an EditText among other views

Upvotes: 1

Views: 140

Answers (1)

Oya Canli
Oya Canli

Reputation: 2516

Within the data tags, import the EditorInfo class:

<data>
    <import type="android.view.inputmethod.EditorInfo"/>
</data>

And set it like:

customEditText:imeOptions="@{EditorInfo.IME_ACTION_DONE}"

Upvotes: 1

Related Questions