androidlistviewlistviewitem

make listview show only the first line of each item


i want to make a listview items show only one line with ... in the end when the string of the item is more then one line just like this

item 1 is very good.

i want to make it looks like this

item 1 ....

because the list view bounds will be at "is" So, I don't want to have only a one line I have a basic action bar activity with list view layout and the XML code is

<?xml version="1.0" encoding="utf-8"?>`
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

Note that the items will be added dynamically.

Thanks


Solution

  • Please add these two line on your textview of listview adapter item.

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

    singleLine is depricated so please use maxLines like

    android:maxLines="1"
    android:ellipsize="end"