You need to add the TextView to the layout.
Here's the revised program:
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.AbsoluteLayout;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
AbsoluteLayout layout = new AbsoluteLayout(this);
TextView tv = new TextView(layout.getContext());
tv.layout(10,10,100,100);
tv.setText("Hello World! :-)");
layout.addView(tv);
setContentView(layout); }
}
On Dec 25, 7:59 am, Martin <[email protected]> wrote:
> Hi!
>
> Why doesn't write this program "Hello World! :-)" on my screen?
> I know how I would do it with an xml-file, but I want to do it like
> in the following program.
> And how can I set the coordinates without setting the width and height
> like with tv.layout(10,10,100,100); ?
>
> Greetings, Martin
>
> -----------------------------------------------------------------------
>
> package com.example.helloandroid;
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.widget.AbsoluteLayout;
> import android.widget.TextView;
>
> public class HelloAndroid extends Activity {
> /** Called when the activity is first created. */
> �...@override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> AbsoluteLayout layout = new AbsoluteLayout(this);
> TextView tv = new TextView(layout.getContext());
> tv.layout(10,10,100,100);
>
> tv.setText("Hello World! :-)");
> setContentView(layout);
> }
>
>
>
> }
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en