[英]Android Data Binding comparison in xml
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?但这并不像我计划的那样有效,我想做一个 IF,如果容量长度 > 3,那么如果不这样做,就这样做......但我认为? means if its null and not true.. so any clue on how to achieve that?
意味着如果它的 null 不是真的..那么关于如何实现它的任何线索?
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()}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.