Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6968747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:29:31+00:00 2026-05-27T16:29:31+00:00

I have a TextView whose contents are copied from a text file. Now each

  • 0

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 :

    <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" >

        <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" >

            <requestFocus />
        </TextView>
    </ScrollView>

And this is what the function looks like :

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);
        }
    });
}

Now I found a partial solution over here.
Hence the last line bit of code that says :

((ScrollView) findViewById(R.id.scroller)).post(new Runnable() 
{
    public void run() 
    {
        ((ScrollView) findViewById(R.id.scroller)).fullScroll(View.FOCUS_DOWN);
    }
});

But this works only the first time the text file is loaded. How do I always make the TextView scroll down to the end?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:29:32+00:00Added an answer on May 27, 2026 at 4:29 pm

    EDIT:
    Use this:

        final ScrollView scroller = (ScrollView) findViewById(R.id.scroller);
        scroller.setOnFocusChangeListener(new OnFocusChangeListener() {
    
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    scroller.fullScroll(View.FOCUS_DOWN);
                }
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following TextView in my XML layout file:- <TextView android:layout_width=fill_parent android:layout_height=wrap_content android:text=@string/autolink_test
I have a gtk.Textview . I want to find and select some of the
I have a custom Dialog that contains only a TextView to display some text
I have a ListView composed of LinearLayouts. Inside each is an ImageView, TextView and
I have an Activity whose layout is in the file main.xml that contains a
I have a view in the XML <TextView style=@style/TitleBarText /> whose styles are defined
I have a Textview with location: eg. Mountain View, CA What I want to
I have a textview which contains chat history obtained from a server.The chat history
I have a textview with a large text, and I would like to find
I have an empty TextView set for my ListView . When there is no

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.