The Dark Knight
The Dark Knight

Reputation: 5583

Make a static text appear on activity load

I have a piece of code like this :

public class myAcitvity extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_mine);
       // Want a text to appear on activity screen after this activity creation , but not a toast.
     }
}

Now once the activity has been created , i want a static text to appear like we do in jsp using <c: out> or out.print() . How do i do that in android ?

Upvotes: 1

Views: 2717

Answers (3)

Scott Helme
Scott Helme

Reputation: 4799

To output to the console use:

Log.i("My Error", "Oops, that didn't go so well..."); 

If you want something to appear in the activity you can add something like a TextView in the activity_mine.xml layout file you have:

 <TextView android:text="My Text"
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
</TextView>

or programtically create a view in the onCreate() method:

TextView textView = new TextView(getApplicationContext());
textView.setText("My text");
layout.addView(TextView, layoutParams); <- get your parent layout and create params

Upvotes: 0

T_V
T_V

Reputation: 17580

You can use Log. but I think your need is something else.

Upvotes: 0

ragzz2014
ragzz2014

Reputation: 56

midify your activity_mine to :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

public class myAcitvity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_mine);
   TextView t = (TextView)findViewById(R.id.textView1);
   t.setText("some static text");
 }

}

Upvotes: 1

Related Questions