Home > OS >  Android Data Binding comparison in xml
Android Data Binding comparison in xml

Time:01-09

im wondering whether i can do this comparison with databinding or not .. i want the field to have an inputmask based on the lenght of the numbers im getting so this is what im trying to do >

app:inputMask="@{state.capacity.length() > 3 ? InputMask.TON : InputMask.KG}"

but this isnt quite working as i planned out , i wanted to do liek an IF , if capacity lenght >3 then do this if not do that .. but i think the ? means if its null and not true.. so any clue on how to achieve that ?

CodePudding user response:

You can use databinding adapter.

@BindingAdapter("myInputMask")
fun setMyInputMask(maskedEditText: MaskedEditText?, capacity: Int?) {
    if (capacity > 3) {
        editText.setMask(InputMask.TON)
    } else {
        editText.setMask(InputMask.KG)
    }
}

app:myInputMask="@{state.capacity.length()}"

  • Related