PDA

View Full Version : easy one: how do I write text to canvas for debugging?



edzillion
10-20-2009, 11:01 AM
Can I just create a textview object and write it to the canvas or do I need to create a layout that inludes the textview in its own area?

A code sample would really help. Thanks.

Paperboat
10-22-2009, 08:46 AM
Not sure if this is what you mean, but you can set the ContentView to your textview object:

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView greeting= new TextView(this);
greeting.setText("Hello World!");
setContentView(greeting);
}

Of course, this is generally not considered good programming practice. It's usually better to isolate view from the data, etc.

Appventive
10-22-2009, 10:39 AM
For debugging I generally use Log.v -- the output goes to the DDMS LogCat window. You can also add a LogCat view in Eclipse (Window/Show View/LogCat).

Cheers,
Steve