Search code examples
androidandroid-scrollbar

Auto scroll down on textviews


I have 3 components on my application, 1 textview(inputType:textMultiline, scrollbar:vertical, gravity:bottom|right) at the top, 1 editview at the middle and 1 button at the bottom. When I type something on my editview and I click the button, the text written on the edit view displays on the textview. Every time i hit ok, the text displays the the bottom and what is displayed is the first three inputs. I have to scroll down the textview in able for me to see my last input.

Now, I want my users to see their last input on their textview. I want to know if there is such code for auto scrolldown for textviews everytime I input a new text on it. I am new on developing android apps. Thanks!


Solution

  • I already got the answer for this! Thank you for giving me some idea. I might be able to use them in the future. @Bharat Sharma, you almost got the answer! Thanks!

    public void onClick(View v) {
                // TODO Auto-generated method stub
                log.setText(log.getText() + "\n" +input.getText());
    
                if(log.getLineCount() > 5){
                    scroll_amount = scroll_amount + log.getLineHeight();
                    log.scrollTo(0, scroll_amount);
                }
            }
    

    I called the variable scroll amount outside the onCreate(). Thanks again!