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.
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"
/>
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"
you can use Code in java :
tv.setSingleLine();
tv.setEllipsize(TextUtils.TruncateAt.MARQUEE);
and xml Code :
android:singleLine="true"
android:ellipsize="end"
Try this:
int charactersLimit = 10;
String yourLargeString = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
String yourFinalString = yourLargeString.substring(0, Math.min(yourLargeString.length(), charactersLimit));
yourTextView.setText(yourFinalString + "...");
you can use code in java
tv=(TextView)findViewById(R.id.txt_comentdata);
tv.setMaxLines(3);
tv.setEllipsize(TextUtils.TruncateAt.END)
You can use XML code:
android:singleLine="true"
android:maxLength="3"
android:ellipsize="end"