Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textview act like a terminal

Hello I am trying to get text to display like it does in terminal or cmd. And by that I mean a window of text that with each input makes a new line and then displays the bottom line of the TextView, and there would be a set amount of lines always on the screen.

It sounded easy to do, but now that I started I'm not sure how to do it.

I tried putting a TextView in a ScrollView like this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="100" >

<ScrollView android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:layout_weight="1">

    <TextView android:id="@+id/tv1" 
        android:layout_width="wrap_content"
        android:minLines="11"
        android:maxLines="11"
        android:layout_height="wrap_content"/>
</ScrollView>

<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="10" >

    <requestFocus />
</EditText>

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="10"
    android:onClick="buttonclick"
    android:text="Button" />

</LinearLayout>

and then

sss=et1.getText().toString();
tv1.append("\n"+sss);

to add new lines

This all works but I really have no idea how to make the TextView go to the bottom, right now it just cuts off when I hit the max number of lines.

I definitely don't expect anyone to write my program for me. I am here to learn

Thanks for your time!

like image 789
DisibioAaron Avatar asked Jan 21 '12 00:01

DisibioAaron


1 Answers

Call fullScroll(View.FOCUS_DOWN) on the ScrollView after appending the text.

like image 95
CommonsWare Avatar answered Sep 21 '22 01:09

CommonsWare