问题
May I know how to limit the length of a text in listView
?
Below is the listView
from wechat
and this is my listView
How to limit the length of text so it will display like this is the work description.Ple...
Any help would be greatly appreciated.
回答1:
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"
/>
回答2:
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"
回答3:
you can use Code in java :
tv.setSingleLine();
tv.setEllipsize(TextUtils.TruncateAt.MARQUEE);
and xml Code :
android:singleLine="true"
android:ellipsize="end"
回答4:
Try this:
int charactersLimit = 10;
String yourLargeString = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
String yourFinalString = yourLargeString.substring(0, Math.min(yourLargeString.length(), charactersLimit));
yourTextView.setText(yourFinalString + "...");
回答5:
you can use code in java
tv=(TextView)findViewById(R.id.txt_comentdata);
tv.setMaxLines(3);
tv.setEllipsize(TextUtils.TruncateAt.END)
回答6:
You can use XML code:
android:singleLine="true"
android:maxLength="3"
android:ellipsize="end"
来源:https://stackoverflow.com/questions/34944322/how-to-limit-a-length-of-a-text-in-android-listview