I have a custom Adapter that renders some items in a ListView. I need to show an icon on the ListView's items, if the item's text is ellipsized, and hide it if there's enough room for the text to finish. I have access to the button in getView method of my adapter (where I set the text) but the ellipses are not added immediately upon setting the text.
Is there any way I can do this?
Here's my TextView markup:
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:id="@+id/list_item_description"/>
So, simply call :
Since the getLayout() cant be called before the layout is set, use ViewTreeObserver to find when the textview is loaded:
And finally do not forget to remove removeOnGlobalLayoutListener when you need it nomore.
I hope I understand your question correctly--if you're looking to end a
TextView
that's too wide for a screen with ellipses, you can add these attributes to yourTextView
:If, however, you want to determine whether a
TextView
is ended with an ellipsis or is displayed fully, I'm not so sure that's possible--it doesn't look like it is. Still, you might want to try thegetEllipsize()
method ofTextView
. I'm not sure whether that returns the point at where the TextView is ellipsized by Android, or where you have set the TextView to be ellipsized.The tricky part is that the view you're working with in
getView
will sometimes have been laid out, and sometimes not, so you have to handle both cases.When it hasn't been laid out, you set a view tree observer to check on the ellipsis once it has been. In the case of recycled views, the layout will already be there and you can check for the ellipsis immediately after setting the text.
You can either set your text to marque. add this in your code might help.....
You can also put a horizontal scrollview for you code....