How to make next and previous buttons by Highlight?

Asked

Viewed 15 times

0

Well, I’m having trouble executing a code to go to the next word in Highlight. I’ve tried a lot of things and I can’t seem to make it work. String text is in HTML, and I do the transformation inside the code itself as you can see. I’ve tried to make some kind of logic with if and Else but nothing works.

I appreciate anyone who can help me:

 btHighlightcpc00.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String criteria = buscarcpc00.getText().toString();
                    String fullText = getString(R.string.textcpc00pt1);
                    String fullText2 = getString(R.string.texto2);

                    if ((fullText + fullText2).contains(criteria)) {
                        int indexOfCriteria = (fullText + fullText2).indexOf(criteria);
                        int lineNumber =  (CPC00Text.getLayout().getLineForOffset(indexOfCriteria));
                        int lineNumber2 =  (CPC00Text.getLayout().getLineForOffset(indexOfCriteria));
                        String highlighted = "<font color='red'>" + criteria + "</font>";
                        String highlighted2 = "<font color='red'>" + criteria + "</font>";
                        fullText = fullText.replace(criteria, highlighted);
                        fullText2 = fullText2.replace(criteria, highlighted2);
                        CPC00Text.setText(Html.fromHtml(fullText));
                        CPC00Text2.setText(Html.fromHtml(fullText2));
                        myscrollcpc00.scrollTo(0, CPC00Text.getLayout().getLineTop(lineNumber));
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.