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?
Add the above code to have a single line in EditText tag in your layout.
This will work for the EditText:
Then I would set a max length for the input text:
Those are the 2 that are needed now.
The @Aleks G OnKeyListener() works really well, but I ran it from MainActivity and so had to modify it slightly:
I hope this helps anyone trying to do the same.
I have done this in the past with
android:singleLine="true"
and then adding a listener for the "enter" key:Use Below Code instead of your code
android:singleLine
is now deprecated. From the documentation:So you could just set
android:inputType="textEmailSubject"
or any other value that matches the content of the field.