title: Android - automatically scroll within AlertDialog TextView
body: <p>I am using an AlertDialog to track a logFile which is updating in real time, and need to automatically scroll to the bottom of the view whenever an extra line is added.</p>
  
  <p>I am able to cast the <code>AlertDialog</code> to a <code>TextView</code> (and e.g. using this TextView alter the text size) but any methods involving scrolling don't work.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>LogFileView.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
  
                  try {
                      String logFile = "/data/data/com.test/test.log";
                      String logFileOutput = getFileOutput(logFile);
                      final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setMessage(logFileOutput).show();
                      TextView textView = dialog.findViewById(android.R.id.message);
                      textView.setTextSize(8);
                      textView.scrollTo(0, textView.getLineCount());
  
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
          }); 
  </code></pre>
  
  <p><code>textView.setTextSize(8);</code> will alter the text size on display</p>
  
  <p><code>textView.scrollTo(0, textView.getLineCount());</code> will do nothing, and the alert dialog, despite having a scrollbar available, will remain focussed on the first line</p>
  
  <p><strong>Update 1:</strong></p>
  
  <p>I see there are a few requests for the dialog creation code/errors in the console output.</p>
  
  <p>Firstly, I am not actually using a separate layout/class to create the dialog. It is applying the default layout associated with (<code>android.R.id.message</code>) to an instance of <code>android.app.AlertDialog</code> and is only constructed within the onClick method for the onClickListener in the code above.</p>
  
  <p>Based on the feedback I've received so far, the code I've most recently attempted to use looks as follows:</p>
  
  <pre><code>LogFileView.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
  
              try {
                  String logFile = "/data/data/com.test/test.log";
                  String logFileOutput = getFileOutput(logFile);
                  final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setMessage(logFileOutput).show();
                  TextView textView = dialog.findViewById(android.R.id.message);
                  textView.setTextSize(8);
                  //textView.scrollTo(0, textView.getLineCount());
                  textView.setMovementMethod(new ScrollingMovementMethod());
                  textView.post(new Runnable() {
                      @Override
                      public void run() {
                          textView.scrollTo(0, textView.getLineCount());
                      }
                  });
  
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      });
  </code></pre>
  
  <p>Secondly, there is nothing appearing in the console when the scroll attempt is made - this simply gets ignored at runtime.</p>
  
  <p>The default layout seemed like it would be fine for my purpose, given it appears like a blank TextView with a scrollbar attached, but I think it may be a sensible next step to use a new custom layout and add a ScrollView and see what happens</p>