Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

restrict edittext to single line

possible duplicate : android-singleline-true-not-working-for-edittext

<EditText      android:id="@+id/searchbox"       android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:lines="1"     android:scrollHorizontally="true"     android:ellipsize="end"     android:layout_weight="1"     android:layout_marginTop="2dp"     android:drawablePadding="10dp"     android:background="@drawable/edittext"     android:drawableLeft="@drawable/folder_full"     android:drawableRight="@drawable/search"     android:paddingLeft="15dp"     android:hint="search..."> </EditText> 

I want to make the above EditText to have only single line. Even if the user presses "enter" the cursor should not get down to the second line. Can anybody help me doing that?

like image 214
Pankaj Singhal Avatar asked Jun 11 '12 10:06

Pankaj Singhal


People also ask

What is Imeoption Android?

android:imeOptions="actionSend" /> You can then listen for presses on the action button by defining a TextView.OnEditorActionListener for the EditText element. In your listener, respond to the appropriate IME action ID defined in the EditorInfo class, such as IME_ACTION_SEND . For example: Kotlin Java.


1 Answers

Use android:maxLines="1" and android:inputType="text"

You forgot the android:maxLines attribute. And refer for android:inputType With your example, below will give this result:

<EditText      android:id="@+id/searchbox"       android:layout_width="match_parent"     android:layout_height="wrap_content"     android:maxLines="1"     android:inputType="text"     android:scrollHorizontally="true"     android:ellipsize="end"     android:layout_weight="1"     android:layout_marginTop="2dp"     android:drawablePadding="10dp"     android:background="@drawable/edittext"     android:drawableLeft="@drawable/folder_full"     android:drawableRight="@drawable/search"     android:paddingLeft="15dp"     android:hint="search..."> </EditText> 
like image 139
Praveenkumar Avatar answered Oct 12 '22 00:10

Praveenkumar