I've just been doing the tutorial on how to make a temperature converter, but the tutorial does not explain how to get rid of the exclamation mark on my edit text input. The error is:
No label views point to this text field with an android:labelFor="+id/#+id/editText1"attribute
The tutorial is http://www.vogella.com/articles/Android/article.html.
Take another look at your XML layout file. You want to have #+id/editText1 as the id. When you reference it, you want to call:
EditText editText1 = (EditText)findViewById(R.id.editText1)
Note that you don't need to write the #+id/ when referencing, only when defining an attribute. Maybe that could be the problem.
Also, if you want to change the text, I have not read the tutorial, but it should be defined inside strings.xml.
Add this to your TextView in the layout xml:
android:labelFor="#+id/editText1"
I don't know why, but it works.
If you prefer to suppress the error using lint, I'll describe below how to figure out the name of the lint warning to suppress.
Full warning message to suppress:
Missing labelFor attribute
No label views point to this text field with an
android:labelFor="#+id/searchTextView" attribute
Text fields should be labelled with a labelFor attribute, provided
your minSdkVersion is at least 17.
If your view is labeled but by a label in a different layout which
includes this one, just suppress this warning from lint.
To suppress it, add the attribute tools:ignore="LabelFor" to the component declaration, for example:
<EditText
android:id="#+id/searchTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_marginStart="62dp"
android:layout_toStartOf="#id/clearTextButton"
android:ellipsize="end"
android:inputType="textLongMessage|textNoSuggestions"
android:maxLines="1"
tools:hint="Search STATICDCA"
tools:ignore="LabelFor" />
To determine that the value was LabelFor, I did as follows in Android Studio:
Open the .xml layout file containing the component
Go to menu option Analyze > Inspect Code
Go to the inspection results at the bottom of the screen
Drill all the way down into the warning
Click the warning
On the right side of the inspection results is a detail view, click the drop-down box labeled "Suppress" and choose "Suppress with #SupressLina (Java) or tools:ignore (XML) or lint.xml"
This automatically added tools:ignore="LabelFor" to my component definition in my xml file
Related
All, we're using the Espresso Accessibility Checking and are getting the following errors for the same view. What's the best way to fix this? Removing the content description fixes the second error but the first still remains. Is there a way to satisfy the Accessibility Checker for TextInputEditText?
https://developer.android.com/training/testing/espresso/accessibility-checking
AccessibilityViewCheckException: There were 2 accessibility errors:
TextInputEditText{id=2131362592, res-name=reason}: View is missing speakable text needed for a screen reader
TextInputEditText{id=2131362592, res-name=reason}: Editable TextView should not have a contentDescription.
I noticed that this error will go away if you set the hint in the TextInputEditText and remove the labelFor in TextInputLayout.
According to Google documentation, setting the hint is the way to tell Accessibility about your view for EditTexts.
When labeling editable elements, such as EditText objects, use the android:hint XML attribute for static elements and the setHint() method for dynamic elements to indicate each element's purpose. (Source)
Also, in Google's example of TextInputLayout, it does not specify that you need to have the labelFor field. (Source)
Code Example:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="#+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/edit_text_hint"/>
</android.support.design.widget.TextInputLayout>
I am aware that this post is in direct contradiction to this post:
Accessibility Check fail when using TextInputLayout. However, doing the things mentioned in that post did not work for me on the latest version of Android.
Code
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="295"
android:background="#drawable/shape_titlebar_background"
android:gravity="center"
android:textColor="#color/color_white"
android:textSize="#dimen/sp_12"/>
Screenshot
The arrow in the red box
How to make it disappear?
Edit
I used #BharaniK's answer .This was only useful in the current activity XML file .
When I create a new activity,It will not be useful in the new activity XML file.And I will reset it .
How to make it disappear in the whole project when I set it up only once?
The arrow mark that you see is the line separator indicated by IDE, as IDE soft-wrapped the lines. The reason why are you seeing for android:background attribute is because the length of that line is higher and it can't indent in the same way as it did for other attributes.
For a better understanding, play around with length of attribute values and text wrap settings in your IDE.
Goto View -> Active Editor and Unmark Use Soft Wraps
This is more a 'is there a more appropriate way' question as I have found a work around.
Some of my table headers are being picked up as spelling errors and underlined in red. Of course, that is not what I would like to see. I have found that using
android:inputType="textNoSuggestions"
does disable the spell check markings. I find it odd (bug?) that this is necessary as the docs state:
inputType: The type of data being placed in a text field, used to help
an input method decide how to let the user enter text.
and there is no input associated with just textView. So is this the only/more appropriate way of avoiding the spell check and also, is this a bug that it is spell checking non-input fields?
UPDATE: per request this is sample xml
<TextView
android:text="ID#"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:typeface="monospace"
android:textSize="14sp"
android:digits="4"
android:textAlignment="gravity"
android:layout_weight="5"
android:gravity="left"
android:singleLine="true"
android:phoneNumber="true"
android:inputType="textNoSuggestions|none">
</TextView>
First, I would try removing the android:digits, android:phoneNumber, and android:inputType attributes.
All of those are more intended for use with fields that allow input (such as EditTexts). It also doesn't look like you are using the android:digits attribute correctly, as the string you provide defines the only allowable characters.
In essence, this combination of attributes is telling Android that your TextView accepts input in the form of telephone numbers that contain only the number 4, that this TextView doesn't accept input of any type, and Android should not provide spellcheck suggestions.
If you are setting the content of the TextView yourself, there really is no reason to try to restrict the content of the TextView with flags such as android:phoneNumber since you are the one controlling that.
I know this is an old thread but removing the following from content XML worked for me:
android:autoText="true"
On later android studio versions try:
android:autoText="true"
inside of the (or any input) in the xml.
On newer versions try:
android:inputType="textNoSuggestions"
I get the warning, "This text field does not specify an inputType or a hint" When I modify a copy of a tutorial code (below)
<EditText android:id="#+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/edit_message"
android:layout_weight="1" />
This works fine, and the warning only comes up if a new blank line is created
I've modified it for a friend with several comments lines explaining what each part of it does however, whenever i add in an extra line in the above (Even a blank line, in this case it's a comment line) I receive the above error
<!--edit text creates a text input box-->
<EditText android:id="#+id/edit_message"
<!-- edit_message is a variable, defined in strings.xml-->
<!-- determines the width of the textField, in this case 0dp means "however long the text is" IE: it will grow to fit however many characters the user types -->
android:layout_width="0dp"
<!-- determines the height of the Text Field -->
android:layout_height="wrap_content"
<!-- The hint is the default value for the text field, it calls on the variable edit_message defined in strings.xml-->
android:hint="#string/edit_message"
<!-- Weight means how much the screen the text field can take up, in this case, the ratio is 1:1 so it can take up however much room is needed, However if a different variable also had the weight of 1, the ratio would be 1:2 and each could take up half the screen -->
android:layout_weight="1" />
Without the comments, the warning is not there
The Reason for this warning is that you haven't set the inputType for this editText. Add the following line:
android:inputType="text"
So it should look like this:
<EditText android:id="#+id/edit_message"
android:inputType="text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/edit_message"
android:layout_weight="1" />
And the warning is gone.
Logically you should get warning in the line
<EditText android:id="#+id/edit_message"
and an error in the next line.
Reason:
When you are placing comment tags, then the closing tag of comment is considered as the illegal closing tag for EditText. So you should even get the following error
Element type "EditText" must be followed by either attribute specifications, ">" or "/>".
and because of the above error the remaining code is not executed and thus you get a warning
This text field does not specify an inputType or a hint
even though android:hint attribute exists in your code.
I just run your code and got my app running properly, when i added the comment it crashes, then i realized that you should not comment inside your XML , it is a principle of XML.
I suggest you to read this article explaning what is a well formed XML and how to comment xml in the right way http://webdesign.about.com/cs/xmlinformation/ht/htcommentxml.htm
Also here has been a discussion about this particularly subject and has been solved as well.
https://stackoverflow.com/a/2073162/2069737
Hope it helps you.
What is the meaning of this warning?
No label views point to this text field with an android:labelFor="#
id/# id/editText1" attribute
Note that the double id (#id/#id) is a problem with the error message text and does not reflect the XML content (which is the correct syntax).
The labelFor is an attribute for accessibility options. You assign this to a label so that if, on a form , user clicks a textedit field , android can know what to read (TalkBack) to user.
The id you assigned to it doesn't seem to be a valid one. why there are two #id in the id? Use ids like this: #id/editText1
I've had the same warning message. It disappeared, when I added a hint to my EditText
android:hint="Some explanation about the input..."
Although I am not familiar with the exact error you have posted. But it definitely sounds like you have done something wrong with the id in the textView. Use id like following in your textView.
android:id="#+id/editText1"
And if you want to set labelFor then use :
android:labelFor="#+id/editText1"
It means that you probably should define a label for this edit text and link them using a labelFor inside that labels definition.
example code:
<TextView
android:id="#+id/my_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:labelFor="#+id/my_editText" <!--the plus sign goes first in the code-->
android:text="I'm a label" />
<EditText
android:id="#id/my_editText" <!--no plus sign if not the first-->
android:layout_width="wrap_content"
android:inputType="text"
android:layout_height="wrap_content" />
and it's not only for text views.
Remove th first '#id/' , use like
android:id="#+id/editText1"
which is the correct format. Keep going.. Best wishes.. :)
I solved it by writing both attributes:
android:id="#+id/editText1"
android:labelFor="#+id/editText1"
Select the editText, go to Properties, then Label for and enter #id/EditText1
If the XML looks correct and you're in a Graphical Layout mode then it's probably using a later version of the Android rendering layout that doesn't support EditText.
In Eclipse and Android Studio there should be a green Android icon with what API version is rendering the layout. Make sure you're using a non W or Wearable API as Android W APIs don't support the EditText element. (EditText is most likely not supported because virtual keyboard space is limited on those devices).
The rendered preview should support EditText in any API 4.X version without a trailing W.