Ellipsize not working for textView inside custom listView

Question!

I have a listView with custom objects defined by the xml-layout below. I want the textView with id "info" to be ellipsized on a single line, and I've tried using the attributes

android:singleLine="true"
android:ellipsize="end"

without success.

If I set the layout_width to a fixed width like e.g.

android:layout_width="100px"

the text is truncated fine. But for portability reasons this is not an acceptable solution.

Can you spot the problem?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5px"
>
<TextView  
android:id="@+id/destination"
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:textSize="22dp"
android:paddingLeft="5px"
/>

<TextView  
android:id="@+id/date"
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:textSize="15dp"
android:paddingLeft="5px"
/>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/info_table"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="5px"
android:paddingTop="10px" 
>
    <TableRow>
        <TextView
        	android:id="@+id/driver_label"
        	android:gravity="right"
        	android:paddingRight="5px"
        	android:text="@string/driver_label" />
        <TextView
        	android:id="@+id/driver" />
    </TableRow>
    <TableRow>
        <TextView
        	android:id="@+id/passenger_label"
        	android:gravity="right"
        	android:paddingRight="5px"
        	android:text="@string/passenger_label" />
        <TextView
        	android:id="@+id/passengers" />
    </TableRow>
    <TableRow>
        <TextView
        	android:id="@+id/info_label"
        	android:gravity="right"
        	android:paddingRight="5px" 
        	android:text="@string/info_label"/>
        <TextView
        	android:id="@+id/info"
        	android:layout_width="fill_parent"
        	android:singleLine="true"
        	android:ellipsize="end" />
    </TableRow>
</TableLayout>

By : aspartame


Answers

I found somewhere this attributes



For me these attribute worked. I tested on API 8 and onwards

In XML



If you put TextView inside a custom ViewGroup you created, make sure to measure it again if you changed the dimension after the measurement.

E.g., I calculated the new dimension in onLayout. Before you call child.layout, call

measureChild(child,
    View.MeasureSpec.makeMeasureSpec(childWidth, View.MeasureSpec.EXACTLY),
    View.MeasureSpec.makeMeasureSpec(childHeight, View.MeasureSpec.EXACTLY));


This video can help you solving your question :)
By: admin