I wrote a simple layout which has an EditText
, but it's showing the following warning message:
“No label views point to this text field”
While searching I found this and it solved that warning message,
but did not get difference between both attributes android:id
and android:labelFor
. Any clarification?
android:id
defines the ID of this view.android:labelFor
references the ID of another view.The
labelFor
is an attribute for accessibility options. You assign this to a label so that if, on a form , user clicks aEditText
field , android can know what to read (TalkBack for low vision users) to user.The
id
Supply an identifier name for this view, to later retrieve it withView.findViewById()
orActivity.findViewById()
.UPDATE:
For example -
Reference: android:id and android:labelFor.
in addition to all answers if u don't use xml files for apps this is a brief explanation what for serves VIEW ID :
(btw in my opinion using xml sucks - my only xml file is manifest :D generated by gradle)
@IdRes - annotation for resource id
ps. ID is mandatory to preserve state of hierarchy view when Activity.onSaveInstanceState(Bundle) is used - so if u create in code (VIEW / WIDGET / LAYOUT etc.) don't forget to set it.