Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: EditText doesn't get ellipsized

I have 2 EditTexts in a linear layout and they don't get ellipsized

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#696969"
            android:layout_marginBottom ="5px">

            <EditText
                         android:id="@+id/addressbar" 
                          android:layout_width="fill_parent" 
                          android:layout_height="wrap_content" 
                          android:layout_marginLeft ="2px"
                          android:layout_marginRight ="1.5px"
                          android:layout_weight="0.35"
                          android:textSize = "15sp"
                          android:singleLine="true"
                          android:editable = "true"
                          android:textAppearance="?android:attr/textAppearanceMedium"
                          android:ellipsize="end"
                          android:imeOptions="actionGo"

                           />
            <EditText android:id="@+id/googlebar" 
                          android:layout_width="fill_parent" 
                          android:layout_height="wrap_content" 
                          android:layout_marginLeft ="1.5px"
                          android:layout_marginRight ="3px"
                          android:background="@android:drawable/editbox_background"
                          android:layout_weight="0.65"
                          android:hint="Google"
                          android:textSize = "15sp"
                          android:singleLine="true"
                          android:ellipsize="end"
                          android:imeOptions="actionSearch"
                           />


            </LinearLayout>

what do you think?

like image 685
Alex1987 Avatar asked Mar 04 '11 21:03

Alex1987


3 Answers

Set this property to edit text. Elipsize is working with disable edit text

android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
android:singleLine="true"
android:editable="false"

or setKeyListener(null); This work for me fine in all Android platforms.

like image 131
Mubarak Avatar answered Nov 17 '22 00:11

Mubarak


I could see comment from many people that is Ellipsize works fine in TextView. But not in EditText! Actually I would say we need to have deep look at the EditText. Because EditText is child of TextView. EditText has capability to get input from user, which doesn't available on TextView. So EditText has KeyListener to observe EditText input key event changes. We have to disable this while you add ellipsize. So Your EditText won't be refreshed every time and you will not lose ellipsize feature.

editText.setKeyListener(null);
editText.setEllipsize(TextUtils.TruncateAt.END);
like image 4
Praveen Kumar Sugumaran Avatar answered Nov 16 '22 23:11

Praveen Kumar Sugumaran


Ellipsize is broken: Ellipsize not working for textView inside custom listView

Bug Report: http://code.google.com/p/android/issues/detail?id=882

I had to do the following to get mine working...took a bit of fiddling

android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
like image 2
Will Tate Avatar answered Nov 17 '22 00:11

Will Tate