How to set android:ellipsize with both properties i.e.. end & marquee?

288 views Asked by At

I am facing problem while setting android:ellipsize in listview. Actually as per my requirement when textview(in list view row xml file) is having 32 characters it should append "..." at the end and when user has focus on that list item then it should auto scroll horizontally (which is marquee)

android:id="@+id/navigation_item_text"
        style="@style/PlaylistNavigationText"
        android:layout_width="204dp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:scrollHorizontally="true"
        android:ellipsize="end"
        android:paddingLeft="20dp"
        android:singleLine="true"
        android:layout_marginRight="42dp"

I have tried few approaches: 1) manually set android:ellipsize="end" in layout file and in listview's setOnItemSelectedListener pragrammatically done that

TextView titleTextView= (TextView) view.findViewById(R.id.navigation_item_text);
                titleTextView.setEllipsize(TextUtils.TruncateAt.MARQUEE);

But the problem is that case it will not change to ... again.

2) Tried On listview adapter tried focuschangelistener on textview

if (hasfocus){
titleTextView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
}else{
titleTextView.setEllipsize(TextUtils.TruncateAt.END);
}

Nothing works. Any suggestion will be welcomed. Thanks

1

There are 1 answers

2
Kushal On

1) Set android:ellipsize="end" in layout file

android:id="@+id/navigation_item_text"
    style="@style/PlaylistNavigationText"
    android:layout_width="204dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:scrollHorizontally="true"
    android:ellipsize="end"
    android:paddingLeft="20dp"
    android:singleLine="true"
    android:layout_marginRight="42dp"

2) Call setSeletected(true) of TextView class

    if (hasfocus){
        titleTextView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
        titleTextView.setSelected(true);
    }

This way you will get your result