1

I am trying to add ellipses to a textview in my listview and it's not working.

Please see my xml definition below.

In this case, it's not coming either on the emulator or the device:

?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:focusable="true">
    <ImageView android:id="@+id/imageview" android:layout_width="30dip"
        android:layout_height="30dip" android:layout_centerVertical="true"
        android:layout_alignParentLeft="true" android:src="@drawable/about"
        android:layout_margin="8dip"/>
    <TextView android:id="@+id/title" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_toRightOf="@+id/imageview"
        android:textStyle="bold" android:textColor="#000000"
            android:textSize="15sp" android:lines="1" 
        android:ellipsize="marquee" android:inputType="text"
        android:marqueeRepeatLimit="3" 
        android:layout_marginRight="15dip"
        android:layout_centerVertical="true"
                android:layout_toLeftOf="@+id/delete">
    </TextView>
    <ImageButton android:id="@+id/delete" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_centerVertical="true"
        android:layout_alignParentRight="true" android:layout_marginRight="0dip"
        android:layout_margin="5dip" android:src="@drawable/delete_icon"
        />


</RelativeLayout>

And in this case, it's coming on the emulator, not on the device:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <ImageView android:id="@+id/imageview"
    android:layout_width="wrap_content"
            android:layout_height="wrap_content"
                         android:layout_centerVertical="true" android:layout_alignParentLeft="true"/>
        <TextView android:id="@+id/title" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_toRightOf="@+id/imageview"
             android:textStyle="bold" android:textColor="#000000"
             android:layout_marginLeft="10dip" android:layout_marginRight="10dip"
            android:textSize="15sp"  android:cacheColorHint="#00000000"> 
        </TextView>
        <TextView android:id="@+id/shortdesc" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_below="@+id/title"
            android:layout_toRightOf="@+id/imageview" 
             android:textSize="15sp"
            android:lines="2" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever"
             android:layout_marginLeft="10dip" android:layout_marginRight="20dip"
            android:textColor="#413839"  android:cacheColorHint="#00000000">

        </TextView>


</RelativeLayout>

Please help, thanks for your input and time


The solutions For the first one pls see my commnets below

For the second one, i had to replace marquee with end

<TextView android:id="@+id/shortdesc" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_below="@+id/title"
        android:layout_toRightOf="@+id/imageview" 
         android:textSize="15sp" 
        android:maxLines="2"  android:ellipsize="end" 
         android:layout_marginLeft="10dip" android:layout_marginRight="30dip"
        android:textColor="#413839"  android:cacheColorHint="#00000000"
        android:text="asdfghjmsbvhsfadk vcdfkhreouhjkjfdgdslkfdn bfoiunbf m,cvbkjnfgb kj      nbcdjfkdleoig;dkf nmvnb safdsfrtgdfgdfhg">
    </TextView>
blahdiblah
  • 33,069
  • 21
  • 98
  • 152
png
  • 4,368
  • 7
  • 69
  • 118
  • Can you clarify what you want? Your code and your question seem to be contradictory. – jprofitt Jan 05 '12 at 02:39
  • these are my xml layout. I have defined ellipses but its not getting displayed. In the second case its coming on emulator not on device and in the first case ellipse not coming either on emulator or device. Thank you – png Jan 05 '12 at 03:03

2 Answers2

2

if its not working in listview try to first display ellipsized textview as a standalone view listview some time can complicate things. and also try to use attribute "singleLine=false"

also have a look at this question: lots of info related to ellipse sizing the textview.

updated: my textview working perfectly in my app

<TextView 
    android:id="@+id/product_desc" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@id/img_disclosure"
        android:layout_marginTop="5dip"
        android:layout_marginRight="5dip"
        android:ellipsize="marquee" 
        android:text="this is the sample text to test the ellipsize effect of text view"
        android:textColor="@color/results_sep_color" 
        android:textSize="15sp"
        android:textStyle="bold"
        android:singleLine="false"
        android:maxLines="2"/>

Second update:

<TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:lines="1"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:text="Don't have an account sdsadfsf asdfsdfdsdd abracadabra"

      />
Community
  • 1
  • 1
dcool
  • 4,039
  • 3
  • 16
  • 14
  • thank you.. i had tried it as just a layout , not as part of list.. but negative result. I have same settings as yours and all the options that i had searched and found.. For me its single line to be ellipsized – png Jan 05 '12 at 06:24
  • i tried your example. It is working as such , but when i try make maxLines = 1 it doesnt work. – png Jan 05 '12 at 06:52
  • hey try the second update to my answer..it surely will work i tried it on android 2.1 device moto milestone. I have just removed all the redundant attributes for the sake of simplicity. – dcool Jan 05 '12 at 06:56
  • yes , i just saw this http://code.google.com/p/android/issues/detail?id=10554 .. its an issue and only android:singleLine="true" is required as workaround. Thanks – png Jan 05 '12 at 07:09
  • neither of these work for me on Samsung G Note 4.0.3, the only difference i am doing is setting the width of the box instead of wrap content (which is the only reason why you would need to be elipsized right?) – Aiden Fry Apr 12 '13 at 11:35
  • can u please put ur layout here – dcool Apr 15 '13 at 05:03
0

There is no need to set attribute like android:scrollHorizontally and android:lines, just set android:singleLine="true" and android:ellipsize="marquee", it works.

Notice: The marquee animation starts when row of ListView has selected.

public void setSingleLine(boolean singleLine) {
    // Could be used, but may break backward compatibility.
    // if (mSingleLine == singleLine) return;
    setInputTypeSingleLine(singleLine);
    applySingleLine(singleLine, true, true);
}

private void applySingleLine(boolean singleLine, boolean applyTransformation,
        boolean changeMaxLines) {
    mSingleLine = singleLine;
    if (singleLine) {
        setLines(1);
        setHorizontallyScrolling(true);
        if (applyTransformation) {
            setTransformationMethod(SingleLineTransformationMethod.getInstance());
        }   
    } else {
        if (changeMaxLines) {
            setMaxLines(Integer.MAX_VALUE);
        }   
        setHorizontallyScrolling(false);
        if (applyTransformation) {
            setTransformationMethod(null);
        }   
    }   
}

android.widget.TextView code snippet (since 1.5_r4).

Gasol
  • 2,319
  • 17
  • 27