try this, in the layout you are building off of put the following:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:id="@+id/ll"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
In the code, do the following:
import android.app.Activity;
import android.os.Bundle;
import android.app.Activity;
import android.os.Bundle;
import android.text.Layout;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.graphics.Color;
public class helloworld extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv1 = new TextView(this);
tv1.setText("This is sample.");
tv1.setTextColor(Color.RED);
//setContentView(tv1);
LinearLayout k = (LinearLayout) findViewById(R.id.ll);
k.addView(tv1);
TextView tv2 = new TextView(this);
tv2.setText("This is yellow.");
tv2.setTextColor(Color.YELLOW);
//setContentView(tv2);
k.addView(tv2);
}
}
On May 1, 12:04 pm, "[email protected]" <[email protected]> wrote:
> Hi
> I will create twi TextView in the main layout, but only last
> TextView can be showed.
>
> My codes:
>
> package myapp.helloworld;
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.widget.TextView;
> import android.graphics.Color;
>
> public class helloworld extends Activity {
> /** Called when the activity is first created. */
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.main);
>
> TextView tv1 = new TextView(this);
> tv1.setText("This is sample.");
> tv1.setTextColor(Color.RED);
> setContentView(tv1);
>
> TextView tv2 = new TextView(this);
> tv2.setText("This is yellow.");
> tv2.setTextColor(Color.YELLOW);
> setContentView(tv2);
> }
I think it will achieve what you are looking for.
John aka Radiolistener
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---