EditText warning in android app development - android

While declaring EditText in xml file, I was warned exactly as given below
No label views point to this text field with an android:labelFor="#+id/#+id/start" attribute
EditText code is
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/start"
android:hint="#string/edit_message" />

I also had no idea what this error message was trying to inform me to do!
Thankfully I found an explanation: http://thecodeiscompiling.blogspot.com/2013/12/android-labelfor-waning-fix.html
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.

Solution for this warning:
No label views point to this text field with an android:labelFor="#+id/#+id/editText1" attribute
When you drag and drop and Text Fields into Graphical Layout you get this above error .
The generated code looks like this:
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="31dp"
android:layout_marginTop="154dp"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
Solution :
add this label "android:labelFor="#+id/editText1" as shown below .
<EditText
android:id="#+id/editText1"
android:labelFor="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="31dp"
android:layout_marginTop="154dp"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>

Use id like following in your editText.
android:id="#+id/editText1"
And then if you want to set labelFor then use
android:labelFor="#id/editText1"

Use android:labelFor="#+id/start" instead of android:id="#+id/start".

Related

Can't focus EditText

I have a simple EditText inside my scrollview.
All the other elements are working just fine, however i won't get the usual EditText behaviour on click (Keyboard doesn't appear, I can't write).
Here's my xml for the field.
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/enterWishprice"
android:background="#drawable/edit_back"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="0 F€"
android:gravity="center_vertical|center_horizontal"
android:textSize="26dp"
android:inputType="number"
android:layout_margin="10dp" />
As you can see I already tried setting focusable/inTouchMode.
I also tried setting a click listener on the field to manually open the keyboard which works just fine. However I still can't type anything into the field.
After that i tried using requestFocus in the clicklistener without any result.
Furthermore I tried clearFocus on the EditText as well as the surrounding ScrollView - also not working.
Hopefully you can give me a hint cause I'm out of ideas..
Thanks in advance!
The attribute Enabled must be set to true.
<EditText
android:id="#+id/room_message"
android:layout_width="164dp"
android:layout_height="46dp"
android:clickable="true"
android:ems="10"
android:enabled="true"
android:focusableInTouchMode="true"
android:hint="#string/prompt_message"
android:inputType="textPersonName"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="italic"
/>
But i have got another problem where the EditText won't lose focus....
try like this
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/enterWishprice"
android:background="#drawable/edit_back"
android:focusableInTouchMode="true"
android:text="0 F€"
android:gravity="center_vertical|center_horizontal"
android:textSize="26dp"
android:inputType="number"
android:layout_margin="10dp">
<requestFocus />
</EditText>

How to make edittext in android both multi line and and initcap

I found out that android:inputType and adding "textMultiLine" and "textCapSentences" makes the input text multiline and init cap respectively, but how can we collaborate both to one edit text?
because error is shown when i put two android:inputType in a single edittext.
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView4"
android:layout_marginTop="28dp"
android:inputType="textCapSentences"
android:ems="10"
android:inputType="textMultiLine" /> // cannot add this here
i tried as per the answer but
the multiline is working but init cap is not working in both this edittext and the ones written as
android:inputType="textCapSentences"
:-(
Use like this..
android:inputType="textCapSentences|textMultiLine"
In your code
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView4"
android:layout_marginTop="28dp"
android:inputType="textCapSentences|textMultiLine"
android:ems="10"/>
inputType attribute (textCapSentence) is IME dependent.
You can achieve your requirement by adding below line:
android:inputType="textCapSentences|textMultiLine"
Still in some keyboards, it will not work. I have also used this and it is working in almost all the keyboards(Nexus, Samsung, HTC) but not in Motorola.

Android Edittext filter for calc

I'm doing a simple calculator.
How do i make a filter for a Edittext to only show numbers and symbols +-*/?
you use digits, for example:
<EditText
android:id="#+id/et_name"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:digits="1234567890-+*/. "
android:maxLength="10" />
now only "1234567890-+*/. " will be allowed in the edittext
this will filter numbers only, though I would suggest that you make buttons that add the number to a plain text view so the user never has the option to edit the text unless they are using the buttons you make, if all you are doing is making an add,subtract,multiply,divide calculator then it would be a much easier way of doing it
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button1"
android:layout_marginBottom="79dp"
android:layout_toRightOf="#+id/textView1"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>

how to fix the size of multiline edit text

I want to make a multi line edit text but the problem is that whenever i enter new line height of edit text increases. how to fix its height. My code is
<EditText
android:id="#+id/editAdditionalInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editPhoneCutomerDetails"
android:layout_alignParentBottom="true"
android:layout_marginBottom="60dp"
android:layout_below="#+id/editPhoneCutomerDetails"
android:layout_marginTop="10dp"
android:background="#drawable/message_additional_box1x"
android:ems="10"
android:padding="10dp"
android:gravity="top">
<requestFocus />
</EditText>
To fix the size of editText you can use
android:singleLine="true"
but it can limit your editText line to 1 .
if you want more lines in editText then use the following property.
Use android:lines="3" .
Use android:lines="2" for fixing multilines and for fixing single line use android:singleLine="true"
for example use like this as shown for multilines
<EditText
android:id="#+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:lines="2"// fix the multiline limit
android:textColor="#000000" />
for example use like this as shown for single line
<EditText
android:id="#+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:singleLine="true"// fix the single line limit
android:textColor="#000000" />
try this;
android:inputType="textMultiLine"
<EditText
android:inputType="textMultiLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
As singleline is now deprecated use inputType:multiline and set the number of lines you want with lines tag
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="4"/>
I had a similar requirement but ended up not changing the size of the box. i.e it grows as text is typed into it but stops short of blocking the other widgets in view. I read this post during my quest and had found a solution. Decided to post it back here. Restricting size to a value may possibly have different effects on different screens. So I think it is better to let it be.
The thing is to put the edit text inside a linearlayout with the rest of the widgets. The code and snapshot are here
Multi line edit box with ok cancel buttons

Edittext jumps to next edittext, but wrong

I need help with my app. This is my xml file with Relative layout, and I need to jump to the next edittext after pressing Enter key.
But there is a problem, if I'm writing to the editTextKm and press Enter key, it jumps to the editTextFullTank, but I need to jump to the editTextManufactYear. How to do it?
<EditText
android:id="#+id/editTextSPZ"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLength="11"
android:inputType="textCapCharacters"/>
<EditText
android:id="#+id/editTextKm"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editTextSPZ"
android:inputType="number"
android:maxLength="7"/>
<EditText
android:id="#+id/editTextManufactYear"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editTextKm"
android:layout_alignBottom="#+id/editTextKm"
android:layout_alignParentRight="true"
android:layout_marginRight="2dp"
android:layout_toRightOf="#+id/editTextKm"
android:inputType="number"
android:maxLength="4" />
<EditText
android:id="#+id/editTextFullTank"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editTextKm"
android:inputType="number"
android:maxLength="3"/>
<EditText
android:id="#+id/editTextReserveTank"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/editTextManufactYear"
android:layout_toRightOf="#+id/editTextFullTank"
android:inputType="number"
android:maxLength="3" />
<EditText
android:id="#+id/editTextNote"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_below="#+id/editTextFullTank"
android:capitalize="sentences"
android:singleLine="false"/>
For further details you can consult Anddroid Developer blog.
Focus movement is based on an algorithm which finds the nearest neighbor in a given direction. In rare cases, the default algorithm may not match the intended behavior of the developer. In these situations, you can provide explicit overrides by using these XML attributes in the layout file:
android:nextFocusLeft="reference"
android:nextFocusRight="reference"
android:nextFocusUp="reference"
android:nextFocusDown="reference"
add the attributes:
android:nextFocusDown="#id/your_next_edit_text_to_focus" to each EditText according to what you need.
You can also use :
android:nextFocusUp="#id/your_next_edit_text_to_focus"
android:nextFocusLeft="#id/your_next_edit_text_to_focus"
android:nextFocusRight="#id/your_next_edit_text_to_focus"

Categories

Resources