0

I have in my layout.xml a TextView with "id = txtLog".

Where do the test results from my application using:

Log.i("Result:", "Value of x = " + x);

for show result in LogCat.

It is possible to show these results "Log.i" within the TextView?

Note: I left a space at the bottom of my application to show the TextView. Like a console.

I would like to display these messages on TextView. If possible create a scroll bar and display every time I use Log.i

I am a beginner, do not know if it is possible. Yet thanks.

Vogatsu
  • 591
  • 1
  • 5
  • 8

1 Answers1

0

I would think

myTextView.setText(myTextView.getText() + "Value of x = " + x + "\n");

would work.

EDIT:

Also, to make the TextView scrollable, you need to set a movement method like so:

myTextView.setMovementMethod(new ScrollingMovementMethod());

EDIT 2:

If you want the information to go to both Log.i and a TextView, then you need a method that holds a reference to the TextView you want to update.

public static void LogToView(TextView myTextView, String title, String message) {
   Log.i(title, message);
   myTextView.setText(myTextView.getText() + title + ":  Value of x = " + x + "\n");
}

Put that in whatever class or in your Activity class. Use it instead of Log.i and the message will be passed to both.

DeeV
  • 35,865
  • 9
  • 108
  • 95
  • Not worked as I wanted. I wanted a method that automatically always added the text in the TextView Log.i but the bottom line. – Vogatsu Apr 24 '12 at 19:28