Skip to content

Instantly share code, notes, and snippets.

@JulienGenoud
Created October 18, 2016 09:06
Show Gist options
  • Save JulienGenoud/bc5cc3b506b6827c5242ec8231f2df75 to your computer and use it in GitHub Desktop.
Save JulienGenoud/bc5cc3b506b6827c5242ec8231f2df75 to your computer and use it in GitHub Desktop.
viewHolder.tvTitle.post(new Runnable() {
@Override
public void run() {
Layout l = viewHolder.tvTitle.getLayout();
SpannableString ss;
if (l.getText().toString().contains("…")) {
String text = l.getText().toString().split("…")[0];
ss = new SpannableString(text.subSequence(0, text.length() - 10) + "…\u00A0\u00A0\u00A0\u00A0");
} else {
String text = l.getText().toString();
ss = new SpannableString(text + "\u00A0\u00A0\u00A0\u00A0");
}
Drawable d = mContext.getResources().getDrawable(R.drawable.clean);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
ss.setSpan(span, ss.length() - 1, ss.length(), Spannable.SPAN_COMPOSING);
Drawable d2 = mContext.getResources().getDrawable(R.drawable.explicit);
d2.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
ImageSpan span2 = new ImageSpan(d2, ImageSpan.ALIGN_BOTTOM);
ss.setSpan(span2, ss.length() - 3, ss.length() - 2, Spannable.SPAN_COMPOSING);
viewHolder.tvTitle.setText(ss);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment