0

I know there is this question How to find text in android through a SearchView or EditText? but its not answering my question properly. I have an EditText in which there will be text. I want to find all the text occurences and highlight it like the Ctrl + F in Google Chrome (Windows). Also, there will be a button like "Find Next". I got a image to tell what I want.

What I want

Got the image from How to find text in android through a SearchView or EditText?

I want all the specific text to be highlighted in yellow and the current text to be highlighted in read. Like the image above.

Community
  • 1
  • 1
FadedCoder
  • 1,517
  • 1
  • 16
  • 36
  • You can use `SpannableString` to achieve coloring to specific substrings. Searching word by word and listing the index range of the matched string found. http://developer.android.com/reference/android/text/SpannableString.html – Jibran Khan Aug 26 '15 at 10:15

1 Answers1

0

i think you can use this code. It should work perfectly for your case, the only difference is that instead of the foreach clause, you will have to use an int

int i = *numberOfRecurrences*;
int index = *recurrenceShown*;

than you can add the next button and foreach click doing

index++;

and than change the background of index recurrences and setting back the color of other recurrences to the default one.

if you have questions ask :)

Community
  • 1
  • 1
Pier Giorgio Misley
  • 5,305
  • 4
  • 27
  • 66
  • Thanks, but can you tell me where to put this code -`int i = *numberOfRecurrences*; int index = *recurrenceShown*;` and `index++;` – FadedCoder Aug 26 '15 at 13:12
  • @AUnknownHacker those are the 2 variables saying how many recurrences are of the word and which is the actual one in evidence. You can set both global and initialize them after the search for recurrences, or you can also set them locally, depending on where you need them :\ – Pier Giorgio Misley Aug 26 '15 at 13:14