Mega Code Archive

 
Categories / Android / Date Type
 

Shorten text for display in lists etc

//package net.bible.service.common; // class CommonUtils {   private static final int DEFAULT_MAX_TEXT_LENGTH = 250;   private static final String ELLIPSIS = "...";   /**    * shorten text for display in lists etc.    *     * @param text    * @return    */   public static String limitTextLength(String text) {     if (text != null && text.length() > DEFAULT_MAX_TEXT_LENGTH) {       // break on a space rather than mid-word       int cutPoint = text.indexOf(" ", DEFAULT_MAX_TEXT_LENGTH);       if (cutPoint >= DEFAULT_MAX_TEXT_LENGTH) {         text = text.substring(0, cutPoint + 1) + ELLIPSIS;       }     }     return text;   } }