Console textview android

I'm new in android developement. I'm doing an application that will go through some process and in the process, something happens. So I want a visual console in my activity screen to see what is going on. The idea is a textview in which I insert lines and it has to be refreshed always in the last line and be able to scroll to the start.

How can I do this in code?

Thanks

Answers


If you have a simple TextView with a fixed size, within a ScrollView, it will behave exactly like you want. The only thing you have to do is make sure you don't overwrite the existing text each time, but append it to the end. Keep a reference to the actual content of the TextView (a simple String would do), and update it accordingly, then use myTextView.setText(newValue)

When you set the text to the TextView, the view will be refreshed automatically.

<ScrollView android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:layout_weight="1">
    <TextView android:id="@+id/textView" 
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"/>
</ScrollView>

And in your activity, when you want to add newText to your view:

this.currentText += "\n" + newText;
final TextView myTextView = (TextView) findViewById(R.id.textView);
myTextView.setText(currentText);

And finally I would also recommend to scroll down to the last line: call fullScroll(View.FOCUS_DOWN) on the ScrollView.


Need Your Help

problem on setting up ruby on rails

ruby-on-rails ruby

I just started learning ruby on rails with "Lynda Ruby on Rails 3 Essential Training".

iOS Objective C Method issue

ios methods call declare

I am trying to port a project of mine from Android to iOS and I am running into some fundamental issues that have been vexing. Like currently for instance I can't call a method I created because it

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.