Pankaj Singhal Pankaj Singhal - 6 months ago 33
Android Question

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???

Thanx.

Answer

Use android:singleLine

You forgot this one android:singleLine

<EditText 
    android:id="@+id/searchbox"  
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    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>