1

I have a TextView which is filled with 500+ words and I wish to programmatically vertically scroll the contents to a certain phrase. I thought I had this solved using tv.scrollTo(x,y) however despite scrolling to the correct position, I can no longer manually scroll back up past the position. It's as if the previous words are no longer in the view.

int offset = tv.getText().toString().indexOf("the text i wish to scroll to");
tv.scrollTo(0, tv.getLayout().getLineTop(tv.getLayout().getLineForOffset(offset)));

I've also tried with

tv.scrollTo(0, tv.getLayout().getLineTop(tv.getTop() + tv.getLayout().getLineForOffset(offset)));

Note my TexView is not in ScrollView container, so I am not trying to scroll the tv within a scrollview but instead scroll vertically the text within the tv itself. As it would be by a user using their finger.

So what is the correct command / way to scroll a textview to a certain position based on specific text content which still allows the user to manually scroll back to text in the textview prior to the found position?

spazm
  • 3,545
  • 26
  • 29
  • Possible duplicate of [Making TextView Scrollable in Android](http://stackoverflow.com/questions/1748977/making-textview-scrollable-in-android) – David Medenjak Mar 11 '16 at 18:20
  • The linked question and answers does not address my issue which is the text prior to the scrolled position is lost. – user3298021 Mar 11 '16 at 18:53

0 Answers0