How to create two TextView without write the XML file

by rjy...@gmail.com » Mon, 04 May 2009 05:57:27 GMT


Sponsored Links
 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);
    }

--~--~---------~--~----~------------~-------~--~----~



How to create two TextView without write the XML file

by radiolistener » Mon, 04 May 2009 10:44:00 GMT


 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);
    }
}





I think it will achieve what you are looking for.
John aka Radiolistener
--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Call the default mediaplayer program in Android OS

Does anyone know to built an application to call the default
mediaplayer program in Android OS ?
--~--~---------~--~----~------------~-------~--~----~

2. Any MediaPlayer success?

Has anyone had any success with the MediaPlayer class? I haven't been able
to play a single 3gp file. I've also tried a few MPEG-4 files. I've
downloaded maybe 30+ random small files from the internet. They play fine in
PC players (I'm testing with VLC) but no luck on the emulator. I've tried
files as small as a few kb up to 5MB.

Is there a place to find out the expected file structures for MediaPlayer?

Also, does anyone have any video files recorded with MediaRecorder on an
actual G1? I'd like to examine the recorded file structure in detail with a
hex editor. Thanks!

David

--~--~---------~--~----~------------~-------~--~----~

3. UI Controls

4. sqlite create two tables onCreate...

5. About the IM to show the message received

6. offline topographic mapping applications?

7. How to get the simulator working