5

I have an EditText in my xml and I get this warning

No label views point to this text field with an android:labelFor="@+id/@+id/et_password" attribute

I have searched in SO and I found these posts but unfortunately I don't find any answer that explains the reason of getting this warning.

1- Meaning of "No label views point to this text field" warning message

2- EditText warning in android app development

Here is my xml code:

<LinearLayout
       android:id="@+id/ll_password"
       android:layout_width="match_parent"
       android:layout_height="wrap_content" >

       <TextView
           android:id="@+id/tv_password"
           android:layout_width="0dp"
           android:layout_height="wrap_content"
           android:layout_weight="0.3"
           android:text="@string/tv_password" />

       <EditText
           android:id="@+id/et_password"
           android:layout_width="0dp"
           android:layout_height="wrap_content"
           android:layout_weight="0.7"
           android:background="@color/background"
           android:gravity="start|center_vertical"
           android:inputType="textPassword"
           android:singleLine="true" />
</LinearLayout>

I don't know why I'm getting this warning. What I have done so far:

1- I tried changing my EditText id

2- Removing TextView in my layout

But warning still remain. I just wondered because I have the same LinearLayout for my username without any warning.

Am I doing wrong? And what's the reason I'm getting this warning?

Community
  • 1
  • 1
Milad Faridnia
  • 9,113
  • 13
  • 65
  • 78
  • 1
    have you tried cleaning your project? – Niko Adrianus Yuwono Dec 07 '15 at 06:37
  • 1
    But [Difference between android:id and android:labelFor?](http://stackoverflow.com/q/16896082/2101822) post clearly mentioned :`Specifies the id of a view for which this view serves as a label for accessibility purposes. For example, a TextView before an EditText in the UI usually specifies what infomation is contained in the EditText. Hence, the TextView is a label for the EditText.` so to remove warning add `android:labelFor="@+id/et_password" ` in `TextView` – ρяσѕρєя K Dec 07 '15 at 06:38
  • @ρяσѕρєяK the link is Wrong and cant find this answer please correct the link – Milad Faridnia Dec 07 '15 at 06:56
  • @Milad: Oh! Please see following [Difference between android:id and android:labelFor?](http://stackoverflow.com/questions/24731137/difference-between-androidid-and-androidlabelfor) – ρяσѕρєя K Dec 07 '15 at 06:58
  • @NikoYuwono Yes of course. I've done that warning gone just for a few seconds and it came back :( – Milad Faridnia Dec 07 '15 at 06:59
  • Why Down Vote. Am I doing wrong? or is there any problem with my question. please tell me so I can improve my question. – Milad Faridnia Dec 07 '15 at 07:00

2 Answers2

4

Three chance in my point of view

1) It might be you have done something wrong with the id of the components.Use id like follows.

android:id="@+id/editText1"

2 ) You should not have plus sign in the labelFor id. It should be: android:labelFor="@id/editText1" The plus sign is only used once to generate the id.

3) This error will show in the XML if you simply drag a Multiline Text into a layout.

See this

Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73
  • The link you've mentioned was very helpful. I really appreciate ;) I just added android:labelFor="@+id/et_password" to my TextView and the warning gone. Thanks so much. – Milad Faridnia Dec 07 '15 at 06:54
4

Just want to add some explanation to Anoop's answer. To solve the problem I just added this line to my TextView:

android:labelFor="@id/et_password"

It was not related to id of the EditText.

It was not related to + sign of id.

Here is the final xml code:

 <LinearLayout
       android:id="@+id/ll_password"
       android:layout_width="match_parent"
       android:layout_height="wrap_content" >

       <TextView
           android:id="@+id/tv_password"
           android:layout_width="0dp"
           android:layout_height="wrap_content"
           android:layout_weight="0.3"
           android:labelFor="@id/et_password"
           android:text="@string/tv_password" />

       <EditText
           android:id="@+id/et_password"
           android:layout_width="0dp"
           android:layout_height="wrap_content"
           android:layout_weight="0.7"
           android:background="@color/background"
           android:gravity="start|center_vertical"
           android:inputType="textPassword"
           android:singleLine="true" />
</LinearLayout>
Milad Faridnia
  • 9,113
  • 13
  • 65
  • 78
  • It's so strange, because this final code doesn't work. App couldn't be compiled because of error "No resource found that matches the given name (at 'labelFor' with value '@id/et_password')." – nick Jun 19 '18 at 13:40
  • 1
    Oh! I just changed line `android:labelFor="@id/et_password"` to `android:labelFor="@+id/et_password"` in code, and it works fine only with **+** (plus). – nick Jun 19 '18 at 13:44
  • I didn't need the `@+id` in `labelFor`. The above compiles just fine. – VIN Feb 15 '19 at 17:39