Wednesday, December 26, 2012

Android Simple TextView Example


SIMPLE TEXTVIEW

SOURCE CODE [main.xml] is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                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" />

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

</LinearLayout>

SOURCE CODE [TextViewExample.java] is

package com.TextViewExample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class TextViewExample extends Activity
{

                TextView tv;

                public void onCreate(Bundle savedInstanceState)
{

                                super.onCreate(savedInstanceState);
                                setContentView(R.layout.main);

                                tv = (TextView) findViewById(R.id.textView1);

                                tv.setText("Set Your Text to display here.");

                }
}

The OUTPUT will be


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-Ssixc5Bu6ntPciHWQL-odXUzWrAyS4fHKth9f4VaoAcX-h3r-uyDY1lwrFn6CX0fo9wEHpYiZpGtGZeZhKhBgh1tnQeY6QgQo-NjY8iF5gSpGwhMNi973NRKHJq9ltXkQKsF3yg5nqI/

No comments:

Post a Comment

Popular Posts