Tuesday, 25 October 2011

Android Annoyances: Text Length

It is incomprehensible to me why there are properties that you can set in an XML attribute but not in code. Here is one quite obvious example.

I have an EditText control for text input and I want to limit the length of input to just two characters. No problem, I can do that easily in XML layout:

android:maxLength="2"

The problem is: in some circumstances I want to limit input to only 1 character, and can only do that in code. Surely enough, if there is such an XML attribute, there should be a setMaxLength() method, right? Wrong. The guys who designed Android API just didn’t think it might be needed.

About Me

It's a secret but I have two very different lives. In one life, I am an experienced Mobile Developer with a substantial experience on both iOS and Android platforms. I have many years of Java EE and Web Development in the past. Also, I have published two books, one of them about Apache Tapestry (still in print), the other one about Apache Batik. I've got MSc with Distinction in Enterprise Systems Development from Glasgow Caledonian University and work as a Principal Consultant for Keytree in London.

In my other life, I am a devoted student of those areas of knowledge that come from our Hermetic heritage, predominantly Astrology, Numerology and Alchemy. In this second life, the biggest achievements are my website at www.lunarium.co.uk and a bunch of iOS and Android apps that is constantly being expanded and upgraded. I am also studying towards MA in Cultural Astronomy and Astrology at the University of Wales Trinity Saint David.