How to limit a length of a text in android ListVie

2019-09-21 08:41发布

May I know how to limit the length of a text in listView ?

Below is the listView from wechat

enter image description here

and this is my listView

enter image description here

How to limit the length of text so it will display like this is the work description.Ple...

Any help would be greatly appreciated.

6条回答
唯我独甜
2楼-- · 2019-09-21 09:09

If you set the TextView to both singleLine and ellipsize to end, then you should have the desired result.

For example:

<TextView
   ...
   android:singleLine="true"
   android:ellipsize="end"
/>
查看更多
Lonely孤独者°
3楼-- · 2019-09-21 09:13

Using filter in code (Programmatically in your java class)

InputFilter[] FilterArr = new InputFilter[1];
FilterArr[0] = new InputFilter.LengthFilter(10);
editEntryView.setFilters(FilterArray);

or in your xml file as below

android:maxLength="10"

combined with

android:singleLine="true"
android:ellipsize="end"
查看更多
闹够了就滚
4楼-- · 2019-09-21 09:13

you can use code in java

       tv=(TextView)findViewById(R.id.txt_comentdata);
       tv.setMaxLines(3);
       tv.setEllipsize(TextUtils.TruncateAt.END)
查看更多
地球回转人心会变
5楼-- · 2019-09-21 09:15

Try this:

int charactersLimit = 10;
String yourLargeString = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
String yourFinalString = yourLargeString.substring(0, Math.min(yourLargeString.length(), charactersLimit));
yourTextView.setText(yourFinalString + "...");
查看更多
贼婆χ
6楼-- · 2019-09-21 09:34

you can use Code in java :

tv.setSingleLine();
tv.setEllipsize(TextUtils.TruncateAt.MARQUEE);

and xml Code :

android:singleLine="true"
android:ellipsize="end"
查看更多
闹够了就滚
7楼-- · 2019-09-21 09:34

You can use XML code:

android:singleLine="true"
android:maxLength="3"
android:ellipsize="end"
查看更多
登录 后发表回答