0

In my layout I have a TextView inside a ScrollView. But I am unable to scroll to the bottom of the TextView programmatically.

I have tried with setSelection(int) but the method is undefined for TextView. So can any one help me.

Thanks in advance.

Egor
  • 39,695
  • 10
  • 113
  • 130
monish george
  • 811
  • 7
  • 14
  • You can try these posts [First Link][1] or [Second Link][2] [1]: http://stackoverflow.com/questions/6438061/can-i-scroll-a-scrollview-programmatically-in-android [2]: http://stackoverflow.com/questions/3080402/android-scrollview-force-to-bottom – AnujMathur_07 Apr 24 '13 at 07:38
  • Check this thread. You will find answer to your question: http://stackoverflow.com/questions/6438061/can-i-scroll-a-scrollview-programmatically-in-android – Nickolai Astashonok Apr 24 '13 at 07:39
  • @ AnujMathur_07 and Nickolai Astashonok : thank you guys for pointing me in to the correct direction.I have updated the question with the answer. – monish george Apr 24 '13 at 08:02

1 Answers1

0

Ok finally i got the work around.

TextView tv = (TextView)findViewById(R.id.textView);//my text view
ScrollView sv = (ScrollView) findViewById(R.id.scrollView);//my scrollview
String log ="a Very long text";
tv.setText(log);
sv.post(new Runnable() {
  public void run() {
    sv.scrollTo(0, tv.getHeight());
  }
}); 
monish george
  • 811
  • 7
  • 14
  • 1
    we are srolling the view in **post** method because we need to wait untill the scrollview is completely loaded.before that we will be unable to scroll that. – monish george Apr 24 '13 at 07:59