public static CharSequence commaEllipsize (CharSequence text, TextPaint p, float avail, String oneMore, String more)
Options:
text - text to truncate p - Paint, with which you can measure the text
avail - horizontal width for text
oneMore - string for "1 more" in the current locale
more - a string for "% d more" in the current locale
Usage example:
String text = "Apple, Orange, Mango, Banana"; TextView tv = new TextView(context); float textWidth = tv.getPaint().measureText(text ); String tempStr = TextUtils.commaEllipsize(text, tv.getPaint(), textWidth, "1 more", "%d more"); tv.setText(tempStr);
Update:
TextView title = (TextView) view.findViewById(R.id.listitemThreadsTitle); title.setVisibility(View.VISIBLE); TextPaint p = title.getPaint(); String strTitle = "Moe, Joe, Isaac, Bethany, Cornelius, Charlie"; title.setText(strTitle); float avail = title.getMeasuredWidth(); CharSequence ch = TextUtils.commaEllipsize(strTitle, p, avail, "one more", "%d more"); title.setText(ch);
source share