11 November 2010

What grammar?

My OC side was alarmed when suddenly, my Problems view in Eclipse was filled with warnings on my XML files. Each of my XML files had a warning with it, and that little yellow exclamation mark on the side:
No grammar constraints (DTD or XML schema) detected for the document

So how do you get rid of it? Go to Window > Preferences > XML > XML Files > Validation then set Indicate when no grammar is specified to Ignore. Click on Apply.

Clean up your project (Project > Clean).

If the problem doesn't go away, you may need to re-validate the XML files. Right click on the file then choose Validate from the popup menu. You can also right click on the folder (such as your res folder) and validate from there.

10 November 2010

TextView and MaxLines

I have a TextView (who doesn't?) and I want to adjust its height automatically, depending on the length of the text it will contain. Should be easy. It was, but it took me a couple of minutes to figure it out.

So I want my TextView to be by default one line tall, but be able to expand up to two lines. My initial set up was to set lines=1 and maxLines=2, but it was making the TextView always two lines. Not what I wanted! I went through the documentation again, read each word carefully, and then:
<TextView android:id="@+id/title"
android:text="This is the text" />
So it turned out that you have to set both minLines and maxLines. TADA!