title: How to get the Android TextView to scroll down to the end automatically?
body: <p>I have a TextView whose contents are copied from a text file. Now each time the contents of the text file is loaded into the TextView, I want it to scroll down automatically to the end.
  This is what that portion of my layout XML file has : </p>
  
  <pre><code>    &lt;ScrollView
          android:id="@+id/scroller"
          android:layout_width="fill_parent"
          android:layout_height="match_parent"
          android:layout_above="@+id/command"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/header"
          android:fillViewport="true" &gt;
  
          &lt;TextView
              android:id="@+id/output"
              android:layout_width="fill_parent"
              android:layout_height="132dp"
              android:bufferType="spannable"
              android:editable="false"
              android:enabled="false"
              android:focusable="true"
              android:focusableInTouchMode="false"
              android:freezesText="true"
              android:inputType="textMultiLine"
              android:isScrollContainer="true"
              android:scrollbars="vertical"
              android:text="@string/output" &gt;
  
              &lt;requestFocus /&gt;
          &lt;/TextView&gt;
      &lt;/ScrollView&gt;
  </code></pre>
  
  <p>And this is what the function looks like :</p>
  
  <pre><code>public void displayOutput()
  {
      File sdcard = Environment.getExternalStorageDirectory();
      File file = new File(sdcard,"/Android/data/terminalemulatorlog.txt");
      StringBuilder text = new StringBuilder();
      try 
      {
          BufferedReader br = new BufferedReader(new FileReader(file));
          String line;
  
          while ((line = br.readLine()) != null) 
          {
              text.append(line);
              text.append('\n');
          }
      }
      catch (IOException e) 
      {
          Toast.makeText(getApplicationContext(),"Error reading file!",Toast.LENGTH_LONG).show();
      }
      TextView output=(TextView) findViewById(R.id.output);
      output.setText(text);
      ((ScrollView) findViewById(R.id.scroller)).post(new Runnable() 
      {
          public void run() 
          {
              ((ScrollView) findViewById(R.id.scroller)).fullScroll(View.FOCUS_DOWN);
          }
      });
  }
  </code></pre>
  
  <p>Now I found a partial solution over <a href="https://stackoverflow.com/questions/3087877/scroll-to-last-line-of-tablelayout-within-a-scrollview">here</a>.
  Hence the last line bit of code that says :</p>
  
  <pre><code>((ScrollView) findViewById(R.id.scroller)).post(new Runnable() 
  {
      public void run() 
      {
          ((ScrollView) findViewById(R.id.scroller)).fullScroll(View.FOCUS_DOWN);
      }
  });
  </code></pre>
  
  <p>But this works only the first time the text file is loaded. How do I always make the TextView scroll down to the end?</p>