Created
April 5, 2017 03:59
-
-
Save dron247/e517cc9dbd9a9865ec41658bad18b5ab to your computer and use it in GitHub Desktop.
This code for ViewHolder helps you to shorten your text lines which do not fit into your list item. Smooth scroll as a result.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int maxWidth = viewHolder.viewGroup.getWidth(); | |
TextPaint textPaint = viewHolder.titleView.getPaint(); | |
String title = cursor.getString(ArticlesQuery.TITLE); | |
int chars = textPaint.breakText(title, true, maxWidth, null); | |
if (chars < title.length()) { | |
title = title.substring(0, chars); | |
} | |
viewHolder.titleView.setText(title); | |
// source: http://martinadamek.com/2011/01/04/performance-of-android-listview-containing-textviews/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment