Amira Elsayed Ismail
Amira Elsayed Ismail

Reputation: 9394

search for text of textview android

I have a textview that render a large amount of text and I want search in this text and scroll the textview to it

is there any method in the textview allow me to do that

Upvotes: 0

Views: 193

Answers (1)

Kirill Bubochkin
Kirill Bubochkin

Reputation: 6343

AFAIK there's no such a direct method, but here's some way I would use to achieve it:

  1. Use getLayout() method of a TextView to get access to layout.
  2. Find offset for a text you're searching.
  3. Find the line for this offset using getLineForOffset() method.
  4. Use getLineTop() to find the top coordinate of this line.
  5. Knowing top line coordinate and position of the view itself, compute the scroll offset.

Upvotes: 2

Related Questions