Widget properties: XML layout vs code

Just stumbled upon another annoyance: you can’t trust XML properties. Let’s take the EditText. We could try to disable dictionary suggestions:

android:inputType="textNoSuggestions"

Well does it work? Probably not, at least not with the devices I tested. But when we do exactly the same in code:

promoCodeEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

It works like a charm! Documentation says clearly that these two are equivalent:

textNoSuggestions  

Can be combined with text and its variations to indicate that the IME should not show any dictionary-based word suggestions. Corresponds toTYPE_TEXT_FLAG_NO_SUGGESTIONS.

Well, not quite… 🙂 

One thought on “Widget properties: XML layout vs code

  1. This is soooo silly! I wasted at least couple of hours to figure out this. For some reason all the values you set to inputType property via XML layout are greater than their actual value in code by 1. For example: textPassword results in 129 while InputType.TYPE_TEXT_VARIATION_PASSWORD is equal to 128. The same with all the rest.

Leave a comment