Sunday, December 29, 2013

Android labelFor warning fix


I just updated the manifest of an older project to API 17, and I started getting the oddest warning out of the blue:
No label views point to this text field with an android:labelFor="@ id/@ id/editText1" attribute

I found it was an accessibility item; the warning is telling you the EditText field does not have a TextView that can be read to a user when accessibility is turned on, since you haven't specified one with the android:labelFor attribute.  To fix this warning, simply find the caption label TextView, and point it to the EditText that's causing the warning.  Of course, the pointing is done by the labelFor attribute.

<TextView 
    android:id="@+id/tv_caption
    android:labelFor="@+id/edit_rate"
    android:text="@string/txt_rate">
</TextView >

<EditText 
    android:id="@+id/edit_rate">
</EditText>

What you should expect, then, is when the user taps inside the EditText edit_rate, the caption for that EditText -- in this case, the TextView tv_caption -- is read to the user.

And doing this also eliminates those pesky warnings.