2011-09-08 1 views
1

Bonjour, je fais une opération de recherche dans l'application en utilisant un mot-clé spécifique et en listant le résultat dans une activité de visualisation de liste. Le résultat sera affiché avec 50 caractères avant et après le mot-clé recherché, mais quand je prends 50 caractères, il casse les mots et dans le résultat, des demi-mots ou des lettres simples sont affichés au début et après. Comment pourrais-je ignorer et obtenir des mots completsApplication android Opération de recherche avec des mots brisés

Voici mon code. Merci de m'aider à ce sujet. merci à l'avance

int endindex = searchTextStartIndex + searchTextLength + 50; 
      if (searchTextStartIndex > 50) { 
       startindex = searchTextStartIndex - 50; 
      } 
      if (endindex > datalength) { 
       endindex = datalength; 
      } 
      searchdata = searchdata.substring(startindex, endindex); 
     } catch (Exception e) 

Répondre

0

En supposant un espace mot seperator:

if (searchTextStartIndex > 50) { 
    startindex = searchdata.lastIndexOf(" ", (searchTextStartIndex - 50)); 
} 

if (startindex == -1) startindex = 0; 

int endindex = searchdata.indexOf(" ", (searchTextStartIndex + searchTextLength + 50)); 

if (endindex == -1 || endindex > datalength) { 
    endindex = datalength; 
} 

searchdata = searchdata.substring(startindex, endindex); 
+0

Merci beaucoup qui était un grand help..thanks nouveau – Jes

Questions connexes