Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: singleline = true not working for edittext

I want to restrict the edittext entry to a single line but When I add the line android:singleline = "true", the hint is disappears, and after entering 26 characters the cursor is coming down.

Here's my XML code:

   <EditText                      
            android:background="@drawable/edittxtborder"
            android:id="@+id/reglastname"
            android:singleLine="true"
            android:gravity="center"
            android:hint="@string/reglname"
            android:textSize="12dp" 
   />
like image 879
Randroid Avatar asked Aug 02 '11 08:08

Randroid


People also ask

Is EditText deprecated?

Save this question. Show activity on this post. But it told me editable is deprecated ,you can use inputType instead.

Can you set text in EditText?

In android, we can set the text of EditText control either while declaring it in Layout file or by using setText() method in Activity file.

What is the EditText attribute android inputType used for?

The android:inputType attribute allows you to specify various behaviors for the input method. Most importantly, if your text field is intended for basic text input (such as for a text message), you should enable auto spelling correction with the "textAutoCorrect" value.


3 Answers

add this code in your edittext xml code.

android:ellipsize="end"

this will work.

like image 54
ilango j Avatar answered Oct 20 '22 11:10

ilango j


Use value for the attribute inputType other than textMultiLine. The input will be single line. The attribute singleLine is deprecated.

like image 22
spgodara Avatar answered Oct 20 '22 11:10

spgodara


I checked your code and the problem is with android:gravity="center". Change it to android:gravity="left" and you will be able to see the hint.

like image 41
Vineet Shukla Avatar answered Oct 20 '22 10:10

Vineet Shukla